Re: Trigger Procedure Error: NEW used in query that is not in a rule - Mailing list pgsql-sql

From Pavel Stehule
Subject Re: Trigger Procedure Error: NEW used in query that is not in a rule
Date
Msg-id 162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com
Whole thread Raw
In response to Trigger Procedure Error: NEW used in query that is not in a rule  ("Javier Fonseca V." <fonsecajavier@gmail.com>)
Responses Re: Trigger Procedure Error: NEW used in query that is not in a rule  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
NEW is only plpgsql variable. It isn't visible on SQL level. You
cannot use new.*, you can:

execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b ....

regards
Pavel

2007/8/11, Javier Fonseca V. <fonsecajavier@gmail.com>:
>
>
> Hello.
>
> I'm doing a Trigger Procedure in pl/pgSQL.  It makes some kind of auditing.
>
> I think that it's working alright except for the next line:
>
> EXECUTE 'INSERT INTO ' || quote_ident(somedynamictablename)
> || ' SELECT new.*';
>
> PostgreSQL keeps telling me: "ERROR: NEW used in query that is not in a
> rule".  I think that this NEW problem is because of the scope of the EXECUTE
> statement (outside the scope of the trigger), so it doesn't recognize the
> NEW record.
>
> Maybe I could fix it concatenating column names and the 'new' values but I
> want to do my trigger as flexible as possible (I have several tables to
> audit).
>
> Somebody has any suggestion?
>
> Thanks a lot,
>
> Javier


pgsql-sql by date:

Previous
From: "Javier Fonseca V."
Date:
Subject: Trigger Procedure Error: NEW used in query that is not in a rule
Next
From: hubert depesz lubaczewski
Date:
Subject: Re: Best Fit SQL query statement