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.92) (envelope-from ) id 1j6hWk-0002w7-MI for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2020 21:14: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 1j6hWj-0001qw-AB for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2020 21:14:01 +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 1j6hWi-0001qp-TM for pgsql-general@lists.postgresql.org; Tue, 25 Feb 2020 21:14:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j6hWg-0006gh-NJ for pgsql-general@postgresql.org; Tue, 25 Feb 2020 21:13:59 +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 01PLDu6X020111; Tue, 25 Feb 2020 16:13:56 -0500 From: Tom Lane To: Paul Jungwirth cc: Stanislav Motycka , PG-General Mailing List Subject: Re: a proposal for a new functionality: "SELECT * [EXCEPT col1 [,col2]] In-reply-to: References: <88ec1892-2282-ab67-b2aa-1f69003e2392@gmail.com> Comments: In-reply-to Paul Jungwirth message dated "Tue, 25 Feb 2020 13:00:40 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20109.1582665236.1@sss.pgh.pa.us> Date: Tue, 25 Feb 2020 16:13:56 -0500 Message-ID: <20110.1582665236@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Paul Jungwirth writes: > Not that this is necessarily fatal, but you'd need to avoid parsing > trouble with the other EXCEPT, e.g. > SELECT 1 EXCEPT SELECT 1; Yeah, it doesn't sound like much consideration has been given to that ambiguity, but it's a big problem if you want to use a syntax like this. > Google Big Query was mentioned upthread. I see they require parens, e.g. > SELECT ... EXCEPT (...). I don't think that actually fixes the ambiguity > though. Indeed it doesn't, because you can parenthesize an EXCEPT's sub-queries: regression=# select 1 except (select 2); ?column? ---------- 1 (1 row) In principle, once you got to the SELECT keyword you could tell things apart, but I'm afraid that might be too late for a Bison-based parser. > So it seems they require at least one `*` in the SELECT target list. In > fact the `*` must be the very last thing. Personally I think it should > be as general as possible and work even without a `*` (let alone caring > about its position). I wonder if they aren't thinking of the EXCEPT as annotating the '*' rather than the whole SELECT list. That seems potentially more flexible, not less so. Consider SELECT t1.* EXCEPT (foo, bar), t2.* EXCEPT (baz) ... FROM t1, t2, ... This doesn't have any problem with ambiguity if t2 has a "foo" column, or if t1 has a "baz" column; which indeed would be cases where this sort of ability would be pretty useful, since otherwise you end up with painful-to-rename duplicate output column names. And certainly there is no particular need for this construct if you didn't write a "*". regards, tom lane