0

How can I pass an expression as an argument when calling a trigger function?

create trigger my_trigger
after insert on my_table
for each row
execute function trigger_job(
 'job_name',
 (json_build_object(
 'foo', current_setting('foo', true),
 'bar', current_setting('bar', true)
 ))
);

I know how to call a "normal" function with an expression as an argument, but I can't get it to work calling a function from the trigger. I also know how to read the passed arguments from TG_ARGV[] in the trigger function, but that's beyond this question.

I also tried something simple like:

create trigger my_trigger
after insert on my_table
for each row
execute function trigger_job(
 'job_name',
 (true)
);

But I still get the error:

ERROR: syntax error at or near "("

LINE 6: (true)

^

Update: I am now using an intermediate function. The trigger calls the intermediate function with the single text parameter. That intermediate function builds the second argument and calls the final trigger_job function with both arguments. Simple.

asked Oct 27, 2020 at 14:34

1 Answer 1

2

It cannot be done. From the docs:

The arguments are literal string constants

answered Oct 27, 2020 at 15:11

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.