From: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Javier Fonseca V(dot)" <fonsecajavier(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Trigger Procedure Error: NEW used in query that is not in a rule |
Date: | 2007-08-11 16:10:04 |
Message-ID: | 162867790708110910v414d7cb3x6e7b4cd16fe4ff80@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-sql |
2007/8/11, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2007-08-11 17:21:54 | Re: why it doesn't work? referential integrity |
Previous Message | Tom Lane | 2007-08-11 15:58:03 | Re: timestamp skew during 7.4 -> 8.2 upgrade |
From | Date | Subject | |
---|---|---|---|
Next Message | Javier Fonseca V. | 2007-08-11 18:45:47 | Re: Trigger Procedure Error: NEW used in query that is not in a rule |
Previous Message | Tom Lane | 2007-08-11 15:50:41 | Re: Trigger Procedure Error: NEW used in query that is not in a rule |