Re: Enhancement proposal - detect chain of triggers from inside the trigger

From: Edson Richter <edsonrichter(at)hotmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Enhancement proposal - detect chain of triggers from inside the trigger
Date: 2013-01-15 23:51:33
Message-ID: BLU0-SMTP26073D28AA4B763AE6F626ECF2D0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Em 15/01/2013 21:36, Adrian Klaver escreveu:
> On 01/15/2013 03:30 PM, Edson Richter wrote:
>> I was wondering, would be a nice addition the ability to read the chain
>> of triggers (may be another trigger variable like TG_OP, called
>> "TG_CHAIN" or something else that will be an array with the name of the
>> triggers called before current trigger).
>
> Well for a given table triggers run in alphabetical name order if that
> helps.

The idea is to be to detect the chain of events among different tables.

A similar effect (for debugging purposes) can be achieved altering every
trigger function adding a "RAISE NOTICE 'you are on Trigger n'" at very
beginning, and read the messages after... until it explodes stack space.
But having the chain of calls, you could do something like

IF TG_CHAIN[0] = 'trigger_i_want_detect' THEN
RAISE EXCEPTION 'database called this trigger twice. Check the chain
of events: %', TG_CHAIN;
END IF;

(I know this is only desirable at development and test time, never at
production).

Regards,

Edson

>
>>
>> Would help debug database triggers that have cascaded events.
>>
>> Regards,
>>
>> Edson
>>
>>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ken Tanzer 2013-01-16 00:09:52 Re: Getting Mysql data into Postgres: least painful methods?
Previous Message Adrian Klaver 2013-01-15 23:36:12 Re: Enhancement proposal - detect chain of triggers from inside the trigger