Re: Help with pg_trigger - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Help with pg_trigger
Date
Msg-id Pine.BSF.4.21.0011160926270.78853-100000@megazone23.bigpanda.com
Whole thread Raw
List pgsql-general
Here's the parts that I know of pg_trigger that are useful:
 tgrelid - relation on which the trigger is defined
 tgname - trigger name (not constraint name for fk constraints)
 tgfoid - oid of function that is called
 tgisconstraint - is this a constraint trigger (currently this
                  should only be true for fk constraints unless
                  you actually make your own)
 tgconstrname - the name of the constraint for a trigger with
                tgisconstraint true
 tgconstrrelid - other relation involved in fk constraint.
                 This may become unnecessary in the future, but
                 it's currently needed to drop constraints when
                 you drop the other table involved.
 tgdeferrable - is the constraint DEFERRABLE
 tginitdeferred - is the constraint INITIALLY DEFERRED
 tgnargs - number of arguments
 tgargs - arguments to the trigger.

To get useful information from some of these, you'll probably want
to join them with other system tables.
For tgrelid and tgconstrrelid, something like:
 select tgname, relname from pg_class, pg_trigger where
  tgrelid /*(or tgconstrrelid)*/ = pg_class.oid;

For tgfoid:
 select tgname, proname from pg_proc, pg_trigger where
  tgfoid = pg_proc.oid;

-
 For foreign key constraints, you can get the associated actions
for a constraint by looking at the functions that it calls.
The pronames will look something like:
 RI_FKey_check_ins - this is the insert/update on fk check
 RI_FKey_<*>_upd - this is the update action
 RI_FKey_<*>_del - this is the del action

<*> says the actual action, noaction, restrict, setdefault, setnull,
cascade.

Stephan Szabo
sszabo@bigpanda.com

On Wed, 15 Nov 2000, Jason Davies wrote:

> Hi,
>
> I've been able to use pg_trigger.tgargs to get relationships between foreign
> keys. Now I want to get the update, delete etc. rules. Any idea how?
>
> If possible could you tell me what each of the columns in pg_trigger are for,
> because I have no idea, and I can't find it in the docs.


pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: [HACKERS] Re: PHPBuilder article -- Postgres vs MySQL
Next
From: Frank Joerdens
Date:
Subject: Re: [HACKERS] Re: PHPBuilder article -- Postgres vs MySQL