Re: triggers using row values

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Clarence Gardner <clarence(at)silcom(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: triggers using row values
Date: 2003-04-03 19:30:29
Message-ID: 20030403112815.H82289-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Thu, 3 Apr 2003, Clarence Gardner wrote:

> I'm trying to create a trigger which will pass a value from the row
> into the procedure to execute. All the documentation I can find shows
> only constant arguments being passed. For example,
> CREATE TRIGGER if_dist_exists
> BEFORE INSERT OR UPDATE ON films FOR EACH ROW
> EXECUTE PROCEDURE check_primary_key ('did', 'distributors', 'did');
>
> That doesn't seem very useful. Here's what I'm trying:
> netbill=> create trigger set_stale_1
> netbill-> after insert or update or delete on dns_a for each row
> netbill-> execute procedure set_zone_stale(zid);
> ERROR: CreateTrigger: function set_zone_stale() does not exist
>
> I have a function defined as set_zone_stale(int). How can I call
> it using the zid field from the changed record?

Generally you get a copy of the NEW and OLD (if applicable) rows in your
function. In plpgsql triggers, they're named NEW and OLD, so you can
say things like NEW.zid inside the trigger function.

Also, trigger functions take no arguments (the standard way - the
arguments passed at create trigger time are separate).

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John Wells 2003-04-03 19:37:13 SAPdb vs. Postgresql
Previous Message Lamar Owen 2003-04-03 19:30:00 Re: [NOVICE] Postgres Syslog