From: | Ron Peterson <rpeterson(at)wallacefloyd(dot)com> |
---|---|
To: | Marcin Mazurek <M(dot)Mazurek(at)poznan(dot)multinet(dot)pl> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: trigger, how to determine action calling? |
Date: | 2000-08-31 16:26:13 |
Message-ID: | 39AE8725.E7293525@wallacefloyd.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Marcin Mazurek wrote:
>
> Hi,
> Is it possible to determine easily which action called triger?
> For example:
> CREATE TRIGGER log_znw BEFORE INSERT OR UPDATE ON tab
> FOR EACH ROW EXECUTE PROCEDURE log_tab();
> How to check in called function if it was INSERT or UPDATE?
Sure. Here's a snippet of C that does this. You might like to check
out the sample SPI programs included with the PostgreSQL source (in
/contrib/spi.)
if (!CurrentTriggerData)
elog(ERROR, "nodeinsert: triggers are not initialized");
if (TRIGGER_FIRED_FOR_STATEMENT(CurrentTriggerData->tg_event))
elog(ERROR, "nodeinsert: can't process STATEMENT events");
if (TRIGGER_FIRED_AFTER(CurrentTriggerData->tg_event))
elog(ERROR, "nodeinsert: must be fired before event");
if (TRIGGER_FIRED_BY_INSERT(CurrentTriggerData->tg_event))
trigger_tuple = CurrentTriggerData->tg_trigtuple;
else if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
/* trigger_tuple = CurrentTriggerData->tg_newtuple; */
elog(ERROR, "nodeinsert: must be fired on INSERT, not UPDATE");
else
elog(ERROR, "nodeinsert: must be fired on INSERT, not DELETE");
--
Ron Peterson
Systems Manager
Wallace Floyd Design Group
273 Summer Street
Boston, MA 02210
617.350.7400 tel
617.350.0051 fax
rpeterson(at)wallacefloyd(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Trewern, Ben | 2000-08-31 16:43:16 | INHERITANCE |
Previous Message | Steve Heaven | 2000-08-31 14:57:22 | Re: Error with tcp/ip networking |