Re: How to fire triggers just on "top" level DML

From: "A(dot)M(dot)" <agentm(at)themactionfaction(dot)com>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to fire triggers just on "top" level DML
Date: 2011-01-19 22:43:30
Message-ID: B988F6B6-8351-4984-A393-9FC677D87036@themactionfaction.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Jan 19, 2011, at 5:36 PM, Kevin Grittner wrote:

> "A.M." <agentm(at)themactionfaction(dot)com> wrote:
>
>> Most PLs include some session-specific storage. In PL/Perl, it is
>> %_SHARED. Setting a flag there should do the trick. If you are
>> using a PL which does not have such a notion (like plpgsql), you
>> can add a call in your triggers to a function written in a PL
>> which does support this. Alternatively, a C function which
>> sets/checks a global flag would work as well.
>
> I thought it might come to that. I'm comfortable writing C
> functions, and we're not using any languages so far besides C, SQL,
> and plpgsql, so I'd probably use C. If I'm going that far, though,
> I'd be rather inclined to implement a TG_DEPTH variable (as being
> easier for us to use) and offer it to the community in case there's
> anyone else who would find this useful. If that turns out to be
> harder than I think, I'll fall back to what you outlined here.

If you do implement TG_DEPTH, I am curious as to what the difference between TG_DEPTH==34 and TG_DEPTH==35 could mean. I think it might cause poor coding practice in making decisions based off assumed trigger order execution. Since you only care to distinguish between depth 1 and depth 2 (and not beyond), could you elaborate on a use case where further trigger "depth" information may be useful?

Cheers,
M

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2011-01-19 22:48:34 Re: How to fire triggers just on "top" level DML
Previous Message Kevin Grittner 2011-01-19 22:36:35 Re: How to fire triggers just on "top" level DML