From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Sava Chankov <sava(dot)chankov(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: INSERT RETURNING rule for joined view |
Date: | 2009-06-01 18:35:52 |
Message-ID: | 21167.1243881352@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Sava Chankov <sava(dot)chankov(at)gmail(dot)com> writes:
> Is there a way to make RETURNING return all view columns?
Something like
CREATE RULE _insert AS ON INSERT TO j DO INSTEAD(
INSERT INTO a (id,name) VALUES (NEW.id, NEW.name);
INSERT INTO b (id,surname) VALUES (NEW.id,NEW.surname)
RETURNING id, (SELECT name FROM a WHERE id = b.id) as name, surname
);
This only really works if the insert specifies "id" explicitly, which is
not amazingly desirable. That's not the fault of the RETURNING though,
but of the repeat reference to NEW.id which might be a volatile
expression (ie, nextval()). In some cases it's okay to hack around that
by using currval() the second time, but that just trades off one
unexpected behavior for a different one ...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | björn lundin | 2009-06-01 19:03:46 | Re: newbie table design question |
Previous Message | Douglas Alan | 2009-06-01 18:20:38 | How can I manually alter the statistics for a column? |