Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 77994B5DBC8 for ; Sat, 17 Sep 2011 12:51:19 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 62592-06 for ; Sat, 17 Sep 2011 15:51:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sd-17937.dedibox.fr (sd-17937.dedibox.fr [88.191.100.74]) by mail.postgresql.org (Postfix) with ESMTP id 18C68B5DC5F for ; Sat, 17 Sep 2011 12:51:12 -0300 (ADT) Received: from [192.168.10.3] (AMontsouris-552-1-122-245.w92-140.abo.wanadoo.fr [92.140.121.245]) by sd-17937.dedibox.fr (Postfix) with ESMTPA id 0743A3B8F5; Sat, 17 Sep 2011 17:51:10 +0200 (CEST) Subject: Re: Use select and update together From: Guillaume Lelarge To: Andreas Cc: pgsql-sql@postgresql.org Date: Sat, 17 Sep 2011 17:51:10 +0200 In-Reply-To: <4E74B538.8080902@gmx.net> References: <4E74B538.8080902@gmx.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.3 (3.0.3-1.fc15) Content-Transfer-Encoding: 8bit Message-ID: <1316274671.2203.2.camel@localhost.localdomain> Mime-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/44 X-Sequence-Number: 35844 On Sat, 2011-09-17 at 16:56 +0200, Andreas wrote: > Am 13.09.2011 07:50, schrieb pasman pasmaƄski: > > In 8.4 this syntax is not implemented. > > select * from ( > update tbl set val = 1 where key in ( 1, 2, 3, 4, 5 ) returning * > ) as x > > wouldn't work even in PG 9.1. > So what data structure is coming out of an "update ... returning *" > statement? > It obviously doesn't work like a subquery. > The only way to make something like this work in 9.1 would be: WITH x AS (update tbl set val = 1 where key in ( 1, 2, 3, 4, 5 ) returning *) SELECT * FROM x; -- Guillaume http://blog.guillaume.lelarge.info http://www.dalibo.com