Re: table name firing trigger

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Raphael Bauduin <raphael(dot)bauduin(at)be(dot)easynet(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: table name firing trigger
Date: 2004-08-11 15:48:33
Message-ID: 20040811154833.GA75747@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Scott Marlowe 2004-08-11 16:56:04 Re: Another 'db session' question...
Previous Message Raphael Bauduin 2004-08-11 15:20:16 Re: table name firing trigger