Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VMvVx-0006y7-RF for pgsql-sql@arkaria.postgresql.org; Fri, 20 Sep 2013 07:52:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VMvVx-00058z-64 for pgsql-sql@arkaria.postgresql.org; Fri, 20 Sep 2013 07:52:33 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VMvVw-00058t-Cg for pgsql-sql@postgresql.org; Fri, 20 Sep 2013 07:52:32 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VMvVt-0005XK-5s for pgsql-sql@postgresql.org; Fri, 20 Sep 2013 07:52:31 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VMvVs-0005vq-8z for pgsql-sql@postgresql.org; Fri, 20 Sep 2013 00:52:28 -0700 Date: Fri, 20 Sep 2013 00:52:28 -0700 (PDT) From: ssylla To: pgsql-sql@postgresql.org Message-ID: <1379663548205-5771708.post@n5.nabble.com> Subject: detect initiator of update/delete action MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.9 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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