hakarabakara1

hakarabakara1

Getting tsvectors: error] ** (Postgrex.Error) ERROR 42703 (undefined_column) record “new” has no field “business_id”

I have three modules, a Business which is associated Tags and Categories though join tables business_tags and business_categories. I intent to improve search hits on the business using tsvector on the database and I have a column searchable on the business which initially was built from the business’ name and description. I want to extend this to the tags and categories such that when tags and categories are assigned to the categories, these would be integrated into the searchable column.

Here’s my migration

execute("""

      CREATE OR REPLACE FUNCTION public.businesses_searchable_trigger()
       RETURNS trigger
       LANGUAGE plpgsql
      AS $function$ begin
      update
    businesses b
      set
    searchable = setweight(to_tsvector('pg_catalog.english', coalesce(b.name, '')), 'A') || setweight(to_tsvector('pg_catalog.english', coalesce(b.description, '')), 'D') || setweight(to_tsvector('pg_catalog.english', coalesce(( select string_agg(distinct t.name, ' ') from business_tags bt join tags t on t.id = bt.tag_id where bt.business_id = b.id ), '') ), 'C') || setweight(to_tsvector('pg_catalog.english', coalesce(( select string_agg(distinct c.name, ' ') from business_categories bc join categories c on c.id = bc.category_id where bc.business_id = b.id ), '') ), 'C')
      where
    b.id = coalesce(NEW.business_id, OLD.business_id);

      return coalesce(new, old);
      end;

      $function$
      ;
    """)

    # Triggers on join tables
    execute("""
    CREATE OR REPLACE TRIGGER business_tags_rebuild_searchable_trigger AFTER INSERT OR UPDATE OR DELETE ON business_tags FOR EACH ROW EXECUTE FUNCTION businesses_searchable_trigger();
    """)

    execute("""
    CREATE OR REPLACE TRIGGER business_categories_rebuild_search_trigger
    AFTER INSERT OR UPDATE OR DELETE ON business_categories
    FOR EACH ROW
      EXECUTE PROCEDURE businesses_searchable_trigger();
    """)

When I attempt to insert a business, it breaks with the following error message:

error] ** (Postgrex.Error) ERROR 42703 (undefined_column) record “new” has no field “business_id”

I will appreciate any form of guidance

First Post!

christhekeele

christhekeele

This is coming from this line in your first update businesses trigger:

b.id = coalesce(NEW.business_id, OLD.business_id)

I would guess that businesses.business_id does not exist.

Where Next?

Popular in Troubleshooting Top

ChrisAmelia
Currently reading and experimenting through, which is in 1.6 Chapter 7: Sign up | Phoenix Tutorial (Phoenix 1.6) | Softcover.io In regar...
New
bugnano
Hello everyone. I’m the author of GitHub - bugnano/wtransport-elixir: Elixir bindings for the WTransport WebTransport library · GitHub ,...
New
hyperoceanic
Having read the book, I’m keen to explore Ash a bit more, but I’m falling at the first hurdle - the creation of a new project. Here’s my...
New
ktayah
Environment Oban Pro: 1.7.6 Oban: 2.22.1 Issue When a sub-workflow built with Workflow.put_context/2 is attached to a parent via ...
New
Lotoen
Hello, I am currently using Elixir 1.18.4 and OTP 27 with Linux Mint 22.3 - Cinnamon 64-bit as my operating system. I came across this er...
New
tellemiller
We recently started running Oban with Oban Web on PostgreSQL (AWS RDS gp3) and noticed our oban_jobs buffer cache hit ratio sitting at 65...
New
anotherpit
A graft inside another graft causes Oban.Pro.Workflow.status to recurse forever. oban_pro 1.7.5 defmodule App.NestedGraftRepro.Test do ...
New
Lotoen
Hi, I’m on Linux Mint 22.3 - Cinnamon 64-bit, and I encountered an error when trying to build an elixir phoenix container 577.1 Reading...
New
ndan
Oban.Pro.Migration.up(version: "1.7.0", only: :indexes) fails on partitioned oban_jobs table when upgrading Oban Pro from 1.6 to 1.7 def...
New
hakarabakara1
I have three modules, a Business which is associated Tags and Categories though join tables business_tags and business_categories. I inte...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement