Re: Help with pg_trigger

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: jason(at)netspade(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Help with pg_trigger
Date: 2000-11-16 17:39:28
Message-ID: Pine.BSF.4.21.0011160926270.78853-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)bigpanda(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Frank Joerdens 2000-11-16 18:08:40 Re: [HACKERS] Re: PHPBuilder article -- Postgres vs MySQL
Previous Message The Hermit Hacker 2000-11-16 17:33:08 Re: [HACKERS] Re: PHPBuilder article -- Postgres vs MySQL