Re: Copying data with triggers - Mailing list pgsql-sql

From Tom Lane
Subject Re: Copying data with triggers
Date
Msg-id 27970.966900076@sss.pgh.pa.us
Whole thread Raw
In response to Copying data with triggers  (Keith Wong <keith@e-magine.com.au>)
List pgsql-sql
Keith Wong <keith@e-magine.com.au> writes:
> create function tp_info () returns opaque as '
>     begin
>         -- insert into audit table
>         insert into AudInfo (info_id, some_data, aud_operation_type) values 
> (new.info_id, new.some_data, ''i'');
>         return new;
>     end;
> ' language 'plpgsql';

> create trigger tp_info before insert on Info
>     for each row execute procedure tp_info();

> This doesn't work however. A parse error occurs in the first line.
> I suspect that I cannot insert a record into another table in a trigger. 

You certainly can --- I have apps that do it all the time.  I suspect
maybe the plpgsql parser gets confused by SQL-style comments?  Your
example seems to work fine if I leave out the comment.
        regards, tom lane


pgsql-sql by date:

Previous
From: "jason watkins"
Date:
Subject: copy DELETES to audit table
Next
From: Jan Wieck
Date:
Subject: Re: 8K Limit, whats the best strategy?