Thread: Creating trigger with optional arg?

Creating trigger with optional arg?

From
Wells Oliver
Date:
Is it possible to have a variable number of elements in TG_ARGV in a trigger?

Arguments 1-3 are required, and I'd like a NULL check on TG_ARGV[4] as an optional message, so it could be called in one of two ways:

create trigger tg_mytrig after insert on mytable for each row execute procedure my_trigger('opt1', 'opt2', 'opt3');
create trigger tg_mytrig after insert on mytable for each row execute procedure my_trigger('opt1', 'opt2', 'opt3', 'optional opt4');

With some kind of null check on TG_ARGV[4] inside the trigger.

--

Re: Creating trigger with optional arg?

From
"David G. Johnston"
Date:
On Wed, Jul 22, 2020 at 9:49 AM Wells Oliver <wells.oliver@gmail.com> wrote:
Is it possible to have a variable number of elements in TG_ARGV in a trigger?


see: default_expr

I would expect it to work though I have not tried it myself.

David J.

Re: Creating trigger with optional arg?

From
Wells Oliver
Date:
 I think this is a little different given I'm using the array TG_ARGV and not defined parameters in the signature though, correct?

On Wed, Jul 22, 2020 at 9:59 AM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Wed, Jul 22, 2020 at 9:49 AM Wells Oliver <wells.oliver@gmail.com> wrote:
Is it possible to have a variable number of elements in TG_ARGV in a trigger?


see: default_expr

I would expect it to work though I have not tried it myself.

David J.



--