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 1i8G3P-0006Dd-4d for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 03:45:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8G3O-0004oG-22 for pgsql-general@arkaria.postgresql.org; Thu, 12 Sep 2019 03:45:54 +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 1i8G2h-0005Yi-4b for pgsql-general@lists.postgresql.org; Thu, 12 Sep 2019 03:45:11 +0000 Received: from ook.raf.org ([139.99.156.21]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8FcD-0008IV-24 for pgsql-general@postgresql.org; Thu, 12 Sep 2019 03:17:55 +0000 Received: from localhost (localhost [127.0.0.1]) by ook.raf.org (Postfix) with ESMTP id 424BD5DEA4 for ; Thu, 12 Sep 2019 13:17:44 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at ook.raf.org Received: from ook.raf.org ([127.0.0.1]) by localhost (ook.raf.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZlgMO_RDcUEt for ; Thu, 12 Sep 2019 13:17:43 +1000 (AEST) Received: by ook.raf.org (Postfix, from userid 1001) id D2C3F5DEAB; Thu, 12 Sep 2019 13:17:43 +1000 (AEST) Date: Thu, 12 Sep 2019 13:17:43 +1000 From: raf To: pgsql-general@postgresql.org Subject: update returning order by syntax error question Message-ID: <20190912031743.jfbfj7e5ri5is36t@raf.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, postgresql-9.6.15 I just tried something like: select * from (update tblname t set ... where ... returning ...) order by ...; assuming it would work but it didn't. That's OK. I found on stackoverflow that a CTE can be used to do it: with u as (update tblname t set ... where ... returning ...) select * from u order by ...; What surprises me is the syntax error: ERROR: syntax error at or near "t" LINE 2: tblname t ^ If the syntax was invalid because an update returning statement can't appear in a from clause, I'd expect the error to be at the token "update". 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". Anyone care to explain why the error is what it is? It's no big deal. I'm just curious. cheers, raf