Re: Triggers with arguments

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Scott Holmes <sholmes(at)pacificnet(dot)net>
Cc: pgsql-general(at)postgresql(dot)org (PG-General)
Subject: Re: Triggers with arguments
Date: 2000-07-13 00:17:50
Message-ID: 25967.963447470@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Scott Holmes <sholmes(at)pacificnet(dot)net> writes:
> CREATE FUNCTION del_stxnoted () RETURNS opaque AS '
> DECLARE
> fname alias for $1;
> rkey alias for $2;
> BEGIN
> delete from stxnoted where filename = fname
> and record_key = rkey;
> END;'
> LANGUAGE 'plpgsql';

> create trigger del_location_trig
> after delete
> on location
> for each row
> execute procedure del_stxnoted("location", 'old.wher');

> Postgres will not create this trigger as it does not recognize the function
> del_stxnoted as actually existing.

Uh, the trigger creates just fine for me. I think your problem is
with the way you're trying to get at the trigger arguments in the
function body. There's an example of the right way in the plpgsql
regress test:

create function tg_chkslotname() returns opaque as '
begin
if substr(new.slotname, 1, 2) != tg_argv[0] then
raise exception ''slotname must begin with %'', tg_argv[0];
end if;
return new;
end;
' language 'plpgsql';

create trigger tg_chkslotname before insert
on PSlot for each row execute procedure tg_chkslotname('PS');

create trigger tg_chkslotname before insert
on WSlot for each row execute procedure tg_chkslotname('WS');

The documentation mentions tg_argv[] but doesn't seem to give an example
:-(

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-07-13 00:50:58 Re: Figured it out (psql and Gnu readline)
Previous Message Erich 2000-07-13 00:14:19 Re: Figured it out (psql and Gnu readline)