From: | ssylla <stefansylla(at)gmx(dot)de> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | detect initiator of update/delete action |
Date: | 2013-09-20 07:52:28 |
Message-ID: | 1379663548205-5771708.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Dear list,
I want to create a function on a table that does something before deletion
on a table, e.g. like
create or replace function table1_del() returns trigger as $$
begin
update table1 set column1=
substr(column2,1,10);
insert into table1_hist values (
old.column1;
return OLD;
end;
$$
language plpgsql volatile;
create trigger table1_del
before delete on table1 for each row
execute procedure table1_del();
However, I need to separate this function with an if-statement depending on
how the deletion was initiated.
There are two cases:
1. if the deletion was executed through a user action, both the update and
insert statement of the 'table1_del' function should be executed
2. if the deletion was initiated through a function fired from another
table, only the insert statement should be executed
Is there a way in postgres to detect if an action (here:deletion) was
initiated by user interaction or a function?
Any help greatly appreciated!
Stefan
--
View this message in context: http://postgresql.1045698.n5.nabble.com/detect-initiator-of-update-delete-action-tp5771708.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Luca Ferrari | 2013-09-20 13:47:38 | Re: detect initiator of update/delete action |
Previous Message | Luca Ferrari | 2013-09-19 08:52:36 | Re: xmlElement and \n |