Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8Q8g-0004E3-8K for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 14:32:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8Q8e-0004FI-T3 for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 14:32:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8Q8e-0004F1-FY for pgsql-general@lists.postgresql.org; Thu, 12 Sep 2019 14:32:00 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i8Q8c-0005ks-35 for pgsql-general@postgresql.org; Thu, 12 Sep 2019 14:31:59 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 7098549D; Thu, 12 Sep 2019 10:31:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 12 Sep 2019 10:31:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=j jid+VvZQyf18DFlEzql49PrFS5nQh2V66ZKy4OER2s=; b=GET4Ne32qAS/CJFi3 wqjEBzcr0QniuFFNglGkMFajZoAMUCutO2PWPNhA34JQT1E/I2hP4zxZC7BX60pa N/k2nCma9xUTHY02DZkPw4n/p+4vOAcsHAHcUWcd4UBU2LPzEK00DijFBgATZwY9 aFXpBKHiPWR857EIhtBJTdHqRFHVx44XMGGdz8GgnswB/o8n5ObhwV6U1Z2R0g+M 37cTc5xRylxplzt6FgglA9CzazWwxP9fX2bY4peyDnmVAU7Dzt7sk5mwyN7R9pG6 Hv9usFBZthSvOuEkwQuUsQN/3Aon1ejgNzHXe6ensRYn84B1vtsvXUmZuiKhrvjL /woRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=jjid+VvZQyf18DFlEzql49PrFS5nQh2V66ZKy4OER 2s=; b=QlPuPt6Ohasx+mxcHcB2YRivmcij/etbuzU1aLuLrAmK8uPx6BnSAhzGo igEL9fxSiMfmDjS1phcejjEmjICtrc3+iqtS4hfEn1JixJOnGGJcsvdE1i7IaJNa 86l8NVV3yhK5eigN0NKEE67r5nil2W2z41yFzaRhf3joZMymgqwe5s8M8hSRHEsa jwENV54GKQXKGvXDMu9tTlkBdMXM8r7BETbe9eHH/AUWIt1pSpjvVWpGyz6MShDK c43/8sorqj1SDyGXmdoFwsf4k+XtFJoDiCmkhWbjSSKrlSJLFQd0ebX1CQgPLR76 95qSp4Q01A8ZXs6cWfIzhsmNv3AuQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrtdehgdejhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesthejre dttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmqeenucfkphepudejgedrvddurdduvdelrdduje ehnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhl rghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.3] (174-21-129-175.tukw.qwest.net [174.21.129.175]) by mail.messagingengine.com (Postfix) with ESMTPA id DBC5AD60067; Thu, 12 Sep 2019 10:31:54 -0400 (EDT) Subject: Re: update returning order by syntax error question To: Tom Lane , raf Cc: pgsql-general@postgresql.org References: <20190912031743.jfbfj7e5ri5is36t@raf.org> <13632.1568295845@sss.pgh.pa.us> From: Adrian Klaver Message-ID: <94b68d28-9cab-b640-3693-477f029991ff@aklaver.com> Date: Thu, 12 Sep 2019 07:31:54 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <13632.1568295845@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/12/19 6:44 AM, Tom Lane wrote: > raf writes: >> It's almost as if the parser sees "update" as a possible >> table name (rather than a reserved word) and "tblname" >> as the alias for that table and it's expecting a comma >> or left/right/full etc. when it seess the "t". > > No, it's *exactly* as if that. UPDATE is an unreserved > keyword so it's fully legitimate as a table name. > If you made the syntax be what the grammar is expecting: > > regression=# select * from (update t cross join update t2); > ERROR: relation "update" does not exist > LINE 1: select * from (update t cross join update t2); I am not following. PostgreSQL 11.5 The OP had: with u as (update tblname t set ... where ... returning ...) select * from u order by ...; I tested with: WITH u AS ( UPDATE up_test t SET col_2 = col_2 + 1 WHERE id < 3 RETURNING * ) SELECT * FROM u; BEGIN id | col1 | col_2 ----+------+------- 1 | t | 2 2 | NULL | 3 (2 rows) I'm missing something. > ^ > > regards, tom lane > > > -- Adrian Klaver adrian.klaver@aklaver.com