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 1i8QEq-0004RG-Gx for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 14:38:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8QEp-0000pG-DD for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 14:38:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8QEp-0000p5-2u for pgsql-general@lists.postgresql.org; Thu, 12 Sep 2019 14:38:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8QEm-00065D-KA for pgsql-general@postgresql.org; Thu, 12 Sep 2019 14:38:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8CEcFmK019620; Thu, 12 Sep 2019 10:38:15 -0400 From: Tom Lane To: Adrian Klaver cc: raf , pgsql-general@postgresql.org Subject: Re: update returning order by syntax error question In-reply-to: <94b68d28-9cab-b640-3693-477f029991ff@aklaver.com> References: <20190912031743.jfbfj7e5ri5is36t@raf.org> <13632.1568295845@sss.pgh.pa.us> <94b68d28-9cab-b640-3693-477f029991ff@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Thu, 12 Sep 2019 07:31:54 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19618.1568299095.1@sss.pgh.pa.us> Date: Thu, 12 Sep 2019 10:38:15 -0400 Message-ID: <19619.1568299095@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > On 9/12/19 6:44 AM, Tom Lane wrote: >> No, it's *exactly* as if that. UPDATE is an unreserved >> keyword so it's fully legitimate as a table name. > I am not following. Sure, the WITH thing works too. The point is that given "SELECT ... FROM (UPDATE ...)", there is a workable parse path where UPDATE is treated as a table name. So if you try to put an UPDATE command there, the syntax error isn't thrown till a couple tokens later, where the table-name syntax no longer matches. The OP's question was about why the error was thrown where it was, not about how to do this correctly. regards, tom lane