Re: detect initiator of update/delete action

From: Luca Ferrari <fluca1978(at)infinito(dot)it>
To: ssylla <stefansylla(at)gmx(dot)de>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: detect initiator of update/delete action
Date: 2013-09-20 13:47:38
Message-ID: CAKoxK+6UZF6eEm8kcBApXs76-5V3Q1XqO-Dc=XRWOfP1fB2NqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Sep 20, 2013 at 9:52 AM, ssylla <stefansylla(at)gmx(dot)de> wrote:
> 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

There is nothing that allows a trigger to distinguish such kind of invocation.
However there is a different kind of approach that comes into my mind
and that I would try: within the trigger test for a specific temporary
table and a value into it. In the case the trigger is invoked
"directly" (1) the table will not be created, while in the case of a
trigger chain the other trigger is responsible for populating the temp
table (and the current trigger to truncate it). Of course a drawback
of this approach is that you need to create and populate the temp
table on each trigger of an higher level in the call chain.

Luca

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2013-09-20 16:07:55 unique key problem on update
Previous Message ssylla 2013-09-20 07:52:28 detect initiator of update/delete action