Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D42DA1337B8B for ; Tue, 19 Apr 2011 16:29:55 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 69949-03 for ; Tue, 19 Apr 2011 19:29:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id ED9291337B82 for ; Tue, 19 Apr 2011 16:29:47 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p3JJTl7e007851; Tue, 19 Apr 2011 15:29:47 -0400 (EDT) To: "Daniel Grace" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5987: Rows created by WITH (INSERT ... RETURNING) are not visible to the rest of the query In-reply-to: <201104191854.p3JIsn6a074429@wwwmaster.postgresql.org> References: <201104191854.p3JIsn6a074429@wwwmaster.postgresql.org> Comments: In-reply-to "Daniel Grace" message dated "Tue, 19 Apr 2011 18:54:49 +0000" Date: Tue, 19 Apr 2011 15:29:47 -0400 Message-ID: <7850.1303241387@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/138 X-Sequence-Number: 30057 "Daniel Grace" 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