Re: RETURNING and DO INSTEAD ... Intentional or not? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: RETURNING and DO INSTEAD ... Intentional or not?
Date
Msg-id 25140.1189622446@sss.pgh.pa.us
Whole thread Raw
In response to Re: RETURNING and DO INSTEAD ... Intentional or not?  (Richard Huxton <dev@archonet.com>)
Responses Re: RETURNING and DO INSTEAD ... Intentional or not?
List pgsql-hackers
Richard Huxton <dev@archonet.com> writes:
> Tom Lane wrote:
>> What the RETURNING clause in the rule does is let you define the data
>> that should be returned if the rewritten INSERT had a returning clause
>> to start with.

> Sorry - haven't got a CSV download here, or I'd check myself. Does this 
> just allow an INSERT...RETURNING inside the rule, or could it be 
> something like:
> CREATE RULE ... AS ON INSERT ... DO INSTEAD SELECT f(NEW.test1);

Well, that's what you do if you want to deliberately break the normal
behavior of INSERT, ie, have it fire back data unconditionally.
What the rule definition of RETURNING is intended for is to let you
write rules that support an updatable view that does the right things,
ie INSERT and INSERT RETURNING on the view both do what you'd expect
them to do if the view were a plain table.

Josh, this *is* documented; see the CREATE RULE reference page for full
details, and there's at least passing references here:
http://developer.postgresql.org/pgdocs/postgres/rules-update.html#RULES-UPDATE-VIEWS
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Representation of redirected line pointers in HOT
Next
From: Josh Berkus
Date:
Subject: Re: RETURNING and DO INSTEAD ... Intentional or not?