pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedplpgsql and triggers
2+ messages / 2 participants
[nested] [flat]
* plpgsql and triggers
@ 2005-06-02 11:57 Bart Degryse <Bart.Degryse@indicator.be>
2005-06-06 02:30 ` Re: plpgsql and triggers Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 2+ messages in thread
From: Bart Degryse @ 2005-06-02 11:57 UTC (permalink / raw)
To: pgsql-sql
I'm looking for a way to use a parameter given to a trigger function as
fieldname. It should be something like
create function f_makeupper() returns trigger as '
begin
NEW.TG_ARGV[0] := upper(NEW.TG_ARGV[0]);
RETURN NEW;
end;
' language 'plpgsql';
create trigger "TRIG_tbltest" before insert on tbltest for each row
execute procedure f_makeupper("fieldname");
I can create both the function and the trigger, but on inserting a new
record I get an error telling me that "record 'new' has no field
'tg_argv'"
What am I doing wrong ?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: plpgsql and triggers
2005-06-02 11:57 plpgsql and triggers Bart Degryse <Bart.Degryse@indicator.be>
@ 2005-06-06 02:30 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Fuhr @ 2005-06-06 02:30 UTC (permalink / raw)
To: Bart Degryse <Bart.Degryse@indicator.be>; +Cc: pgsql-sql
On Thu, Jun 02, 2005 at 01:57:26PM +0200, Bart Degryse wrote:
>
> I'm looking for a way to use a parameter given to a trigger function as
> fieldname. It should be something like
> create function f_makeupper() returns trigger as '
> begin
> NEW.TG_ARGV[0] := upper(NEW.TG_ARGV[0]);
> RETURN NEW;
> end;
> ' language 'plpgsql';
As you've discovered, this doesn't work in PL/pgSQL: the above code
references the new row's TG_ARGV column, which doesn't exist. This
comes up frequently; see the list archives for past discussion. The
usual advice is to use a language like PL/Perl, PL/Tcl, PL/Python, etc.
that provides this capability.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-06-06 02:30 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-02 11:57 plpgsql and triggers Bart Degryse <Bart.Degryse@indicator.be>
2005-06-06 02:30 ` Michael Fuhr <mike@fuhr.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox