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
anotherpit
Summary A downstream job that deps on a graft correctly waits for the grafted jobs at one graft level, but stops waiting when the workflo...
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
AstraLuma
Experienced programmer writer her first Elixir, and maybe bit off more than she can chew? I’m trying to start two GenServers, where the ...
New
rayex
For hex package islands_score the source @spec for function format/2 is as such: @spec format(t, keyword) :: :ok Why does it show on 4 ...
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

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement