4

I've created a trigger for table x1 to update a column y with the expression to_tsvector(unaccent(x1.col1 || ' ' || x2.col1)). This trigger function throws:

function unaccent(text) does not exist

Why would this function not exist when a trigger is called, but exist when executed manually? I'm using Supabase to manage this database.

Erwin Brandstetter
186k28 gold badges463 silver badges636 bronze badges
asked May 22, 2022 at 16:12

1 Answer 1

5

The function unaccent() is typically the one installed by the additional module unaccent. See:

Additional modules can be installed to any schema. (I like to use a dedicated schema.) See:

If so, then the schema must be added to the search_path to allow function calls without schema-qualification like you demonstrate.

The obvious explanation for your observation would be that you call the function in one session with an appropriate search_path, and execute the trigger in another session with a different search_path.

To diagnose, add this line to your PL/pgSQL trigger function just before the command calling unaccent() temporarily (and make sure notices are logged or reported to the client, depending on where you look):

RAISE NOTICE 'Current search_path: %', current_setting('search_path');

The simple & safe fix is to schema-qualify the function name. Like:

my_extension_schema.unaccent(text)

But investigate whether schemas and the search_path are handled properly across your DB cluster ...

answered May 22, 2022 at 21:48
1
  • Thank you! I was not aware of the influence of search_path in this case. I thought that these functions were globally accessible. Commented May 22, 2022 at 22:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.