Re: BUG #5987: Rows created by WITH (INSERT ... RETURNING) are not visible to the rest of the query - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #5987: Rows created by WITH (INSERT ... RETURNING) are not visible to the rest of the query
Date
Msg-id 7850.1303241387@sss.pgh.pa.us
Whole thread Raw
In response to BUG #5987: Rows created by WITH (INSERT ... RETURNING) are not visible to the rest of the query  ("Daniel Grace" <dgrace@wingsnw.com>)
List pgsql-bugs
"Daniel Grace" <dgrace@wingsnw.com> writes:
> Description:        Rows created by WITH (INSERT ... RETURNING) are not
> visible to the rest of the query

This is not a bug but the designed behavior.  See
http://developer.postgresql.org/pgdocs/postgres/queries-with.html

particularly this bit:

The sub-statements in WITH are executed concurrently with each other and
with the main query. Therefore, when using data-modifying statements in
WITH, the order in which the specified updates actually happen is
unpredictable. All the statements are executed with the same snapshot
(see Chapter 13), so they cannot "see" each others' effects on the
target tables. This alleviates the effects of the unpredictability of
the actual order of row updates, and means that RETURNING data is the
only way to communicate changes between different WITH sub-statements
and the main query.

            regards, tom lane

pgsql-bugs by date:

Previous
From: "Daniel Grace"
Date:
Subject: BUG #5987: Rows created by WITH (INSERT ... RETURNING) are not visible to the rest of the query
Next
From: Dewin
Date:
Subject: Re: BUG #5985: CLUSTER ... USING can fail with ERROR: index xxx does not belong to table yyy