Skip to main content
added 2 characters in body
Source Link

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)

^

I suspectUpdate: I need to useam now using an intermediate function. The trigger calls the intermediate function with the single text parameter. That intermediate function would buildbuilds the second argument and calls the final trigger_job function with both arguments. Simple.

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)

^

I suspect I need to use an intermediate function. The trigger calls the intermediate function with the single text parameter. That intermediate function would build the second argument and calls the final trigger_job function with both arguments.

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.

added 252 characters in body
Source Link

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)

^

I suspect I need to use an intermediate function. The trigger calls the intermediate function with the single text parameter. That intermediate function would build the second argument and calls the final trigger_job function with both arguments.

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)

^

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)

^

I suspect I need to use an intermediate function. The trigger calls the intermediate function with the single text parameter. That intermediate function would build the second argument and calls the final trigger_job function with both arguments.

Source Link

How to execute a trigger procedure with an expression as an argument?

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)

^