Re: questions on rules

From: Timothy Perrigo <tperrigo(at)wernervas(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: questions on rules
Date: 2004-04-27 14:19:34
Message-ID: E81EE836-9855-11D8-88E0-000A95C4F0A2@wernervas.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It seems that triggers are not inherited, so to get the functionality I
want I'll have to create a trigger for each table. If anyone knows
another way, please let me know!

After you pointed me in the right direction, I was able to create a
trigger procedure which can be called from triggers on various tables
and will log the operation (including the affected table's oid and
name). The procedure is listed below. Thanks for the help!

Tim

create or replace function add_log_entry() returns TRIGGER as '
BEGIN
insert into audit_log(table_oid, table_name, id, operation) values
(TG_RELID, TG_RELNAME, NEW.id, TG_OP);
return NEW;
END;
' language 'plpgsql';

On Apr 27, 2004, at 8:18 AM, Richard Huxton wrote:

> On Tuesday 27 April 2004 13:40, Timothy Perrigo wrote:
>> Thanks for the reply. Do you know if triggers defined on a base table
>> fire for operations on inherited tables? (I.e., if I have an after
>> insert trigger on table "base", and a table "derived" that inherits
>> from base, will inserts into derived cause the trigger on base to
>> fire?)
>
> Hmm - don't know this I'm afraid.
>
>> If so (this is the behavior I would like), is there a way to
>> get the tableoid of the table which caused the trigger to fire?
>
> Here I can help. Check the plpgsql section of the manuals, and there
> you'll
> find a list of special variables available to trigger functions. These
> include table and trigger name.
>
> --
> Richard Huxton
> Archonet Ltd
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2004-04-27 14:25:06 composite type and assignment in plpgsql
Previous Message Juris Krumins 2004-04-27 14:07:19 Temp table problem.