Re: table name firing trigger - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: table name firing trigger
Date
Msg-id 20040811154833.GA75747@winnie.fuhr.org
Whole thread Raw
In response to table name firing trigger  (Raphael Bauduin <raphael.bauduin@be.easynet.net>)
Responses Re: table name firing trigger
List pgsql-novice
On Wed, Aug 11, 2004 at 09:44:42AM +0200, Raphael Bauduin wrote:
> Does a function executed by a trigger know which table fired the trigger?

Yes.

> I'm using the same function for several triggers on different tables.
> Now, I'm passing the table name as argument:
> CREATE TRIGGER "customers_update_log_t" after UPDATE on "customers" for
> each row execute procedure "customers_update_log"('customers');
>
> I wondered if in the function code, we have access to the table name that
> fired the trigger.

You don't say what language you're using, but in PL/pgSQL you can
refer to the table name as TG_RELNAME.

> Also, does the function have access to the type of action that fired the
> trigger?
> Eg, if I create a trigger after update and insert, is it possible to know
> if it's an insert or an update that fired the trigger?

That would be TG_OP.  See the PL/pgSQL "Trigger Procedures" manual page
for more info:

http://www.postgresql.org/docs/7.4/static/plpgsql-trigger.html

If you're using a language other than PL/pgSQL then see that
language's trigger documentation.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-novice by date:

Previous
From: "Taber, Mark"
Date:
Subject: Another 'db session' question...
Next
From: Raphael Bauduin
Date:
Subject: Re: table name firing trigger