Re: trigger functions with arguments

From: Kevin Field <kevinjamesfield(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: trigger functions with arguments
Date: 2009-06-08 12:55:09
Message-ID: 3e35d67c-8b04-4bae-aacf-6b7914e0c7b4@q14g2000vbn.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jun 8, 5:18 am, laurenz(dot)a(dot)(dot)(dot)(at)wien(dot)gv(dot)at ("Albe Laurenz") wrote:
> Kev wrote:
> > I came across this curious behaviour today, at least in the 2009-03-24
> > beta (I can't run a newer beta), that I couldn't find in the docs,
> > although maybe I missed it.
>
> [...]
>
> > So while that is the way to create the trigger itself, the
> > trigger procedure must be created like this:
>
> > CREATE OR REPLACE FUNCTION test() RETURNS trigger AS $BODY$
> > my ($a, $b) = @{$_TD->{args}}; # $a and/or $b may be null, depending on how CREATE TRIGGER was used
> > ...
>
> Maybe it is hidden too well, but the documentation states inhttp://www.postgresql.org/docs/current/static/plpgsql-trigger.html
>
> A trigger procedure is created with the CREATE FUNCTION command, declaring it
> as a function with no arguments and a return type of trigger. Note that the function
> must be declared with no arguments even if it expects to receive arguments
> specified in CREATE TRIGGER - trigger arguments are passed via TG_ARGV,
> as described below.
>
> Yours,
> Laurenz Albe

Thanks, Laurenz, I had missed that. However, I don't think it's in
the best spot: since I was writing a plperl trigger function, it makes
sense for me to read the plperl trigger function docs, and the general
trigger and trigger function docs, but not necessarily the plpgsql
trigger function docs. IMO it should either be in the trigger
function docs for each language, or it should be in the general
trigger function docs, like maybe http://www.postgresql.org/docs/8.3/static/trigger-definition.html
since it talks about return values and such there. That is, if it
actually applies to every language...

Kev

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2009-06-08 13:18:19 Re: Using results from DELETE ... RETURNING
Previous Message Martin Gainty 2009-06-08 12:18:36 Re: PL/PGSQL