Re: [GENERAL] tables referenced from insert...returning

2008-06-23 Thread Tom Lane
"Michael Shulman" <[EMAIL PROTECTED]> writes: > On Mon, Jun 23, 2008 at 8:46 PM, Tom Lane <[EMAIL PROTECTED]> wrote: >> Multiple evaluations of NEW in the text of a rule are a great way >> to cause yourself trouble --- consider what happens if there's >> a volatile function such as nextval() involv

Re: [GENERAL] tables referenced from insert...returning

2008-06-23 Thread Michael Shulman
On Mon, Jun 23, 2008 at 8:46 PM, Tom Lane <[EMAIL PROTECTED]> wrote: > Hmm ... that might be a bug, but in any case, wouldn't it be wiser to do > > CREATE RULE _insert AS ON INSERT TO tv DO INSTEAD > INSERT INTO test (name) VALUES (NEW.name) RETURNING test.*; Well, what I'm really trying to do is

Re: [GENERAL] tables referenced from insert...returning

2008-06-23 Thread Tom Lane
"Michael Shulman" <[EMAIL PROTECTED]> writes: > CREATE RULE _insert AS ON INSERT TO tv DO INSTEAD > INSERT INTO test (name) VALUES (NEW.name) RETURNING NEW.*; > ERROR: invalid reference to FROM-clause entry for table "*NEW*" > LINE 2: INSERT INTO test (name) VALUES (NEW.name) RETURNING NEW.*;

[GENERAL] tables referenced from insert...returning

2008-06-23 Thread Michael Shulman
Hi, What are the rules about what tables/views can be referenced from the RETURNING clause of an INSERT? I am particularly puzzled by the following. Given these definitions: CREATE TABLE test (id serial primary key, name varchar); CREATE VIEW tv AS SELECT * FROM test; This works: CREATE RULE