pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Javier Fonseca V. <fonsecajavier@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Trigger Procedure Error: NEW used in query that is not in a rule
Date: Sat, 11 Aug 2007 10:16:47 +0200
Message-ID: <162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com> (raw)
In-Reply-To: <86d227fd0708110045t16e39442xd35746eb59296362@mail.gmail.com>
References: <86d227fd0708110043q341a2908q67e87570bca89492@mail.gmail.com>
	<86d227fd0708110045t16e39442xd35746eb59296362@mail.gmail.com>

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



view thread (11+ messages)  latest in thread

Message-ID: <162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com>
Permalink:  ../162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com/
Also on:    postgresql.org/message-id/162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pavel.stehule@gmail.com, fonsecajavier@gmail.com
  Subject: Re: Trigger Procedure Error: NEW used in query that is not in a rule
  In-Reply-To: <162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox