From: Pavel Stehule <pavel.stehule@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: 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 18:10:04 +0200
Message-ID: <162867790708110910v414d7cb3x6e7b4cd16fe4ff80@mail.gmail.com> (raw)
In-Reply-To: <2071.1186847441@sss.pgh.pa.us>
References: <86d227fd0708110043q341a2908q67e87570bca89492@mail.gmail.com>
<86d227fd0708110045t16e39442xd35746eb59296362@mail.gmail.com>
<162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com>
<2071.1186847441@sss.pgh.pa.us>
2007/8/11, Tom Lane <tgl@sss.pgh.pa.us>:
> "Pavel Stehule" <pavel.stehule@gmail.com> writes:
> > NEW is only plpgsql variable. It isn't visible on SQL level.
>
> Correct, but:
>
> > You cannot use new.*, you can:
> > execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b ....
>
> You're both overthinking the problem. In recent releases (at least
> since 8.2) you can do it without any EXECUTE. Like this:
>
> regression=# create table mytab (f1 int, f2 text);
> CREATE TABLE
> regression=# create table logt (f1 int, f2 text, ts timestamptz);
> CREATE TABLE
> regression=# create function myt() returns trigger as $$
> regression$# begin
> regression$# insert into logt values(new.*, now());
> regression$# return new;
> regression$# end$$ language plpgsql;
> CREATE FUNCTION
>
I know it Tom. But original question contains
EXECUTE 'INSERT INTO ' || quote_ident(SOMEDYNAMICNTABLENAME) || ' SELECT new.*';
and then he needs EXECUTE (propably).
but new.* in insert is nice feature.
Regards
Pavel Stehule
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, tgl@sss.pgh.pa.us, fonsecajavier@gmail.com
Subject: Re: Trigger Procedure Error: NEW used in query that is not in a rule
In-Reply-To: <162867790708110910v414d7cb3x6e7b4cd16fe4ff80@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