agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: ssylla <stefansylla@gmx.de>
To: pgsql-sql@postgresql.org
Subject: detect initiator of update/delete action
Date: Fri, 20 Sep 2013 00:52:28 -0700 (PDT)
Message-ID: <1379663548205-5771708.post@n5.nabble.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (2+ messages)  latest in thread

Message-ID: <1379663548205-5771708.post@n5.nabble.com>
Permalink:  ../1379663548205-5771708.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1379663548205-5771708.post@n5.nabble.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: stefansylla@gmx.de
  Subject: Re: detect initiator of update/delete action
  In-Reply-To: <1379663548205-5771708.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox