From: Tom Lane <tgl@sss.pgh.pa.us>
To: Paul Jungwirth <pj@illuminatedcomputing.com>
Cc: Stanislav Motycka <stanislav.motycka@gmail.com>
Cc: PG-General Mailing List <pgsql-general@postgresql.org>
Subject: Re: a proposal for a new functionality: "SELECT * [EXCEPT col1 [,col2]]
Date: Tue, 25 Feb 2020 16:13:56 -0500
Message-ID: <20110.1582665236@sss.pgh.pa.us> (raw)
In-Reply-To: <a726ab6a-d814-7623-4b26-9300d0a1dfb4@illuminatedcomputing.com>
References: <d51371a2-f221-1cf3-4a7d-b2242d4dafdb@gmail.com>
<CAALojA9s5nkWezDJZMDj+EsDuwDzpexM0kV_gcP-MZhF00hYRw@mail.gmail.com>
<CAFp7QwpCNq_wuXwaOOjvcaRjC3vVTQZrifbb3EHpPv9ZWiVz+w@mail.gmail.com>
<CAALojA_ycJBcbp4hgbvO21HqX0_jnbRDnpa8fBEm2=GRn++Azw@mail.gmail.com>
<CA+renyWW_wjY7Qsis6fHJL_VQj=274aRD2Tb-k_QYe=aNwEing@mail.gmail.com>
<88ec1892-2282-ab67-b2aa-1f69003e2392@gmail.com>
<a726ab6a-d814-7623-4b26-9300d0a1dfb4@illuminatedcomputing.com>
Paul Jungwirth <pj@illuminatedcomputing.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, pj@illuminatedcomputing.com, stanislav.motycka@gmail.com
Subject: Re: a proposal for a new functionality: "SELECT * [EXCEPT col1 [,col2]]
In-Reply-To: <20110.1582665236@sss.pgh.pa.us>
References: <d51371a2-f221-1cf3-4a7d-b2242d4dafdb@gmail.com> <CAALojA9s5nkWezDJZMDj+EsDuwDzpexM0kV_gcP-MZhF00hYRw@mail.gmail.com> <CAFp7QwpCNq_wuXwaOOjvcaRjC3vVTQZrifbb3EHpPv9ZWiVz+w@mail.gmail.com> <CAALojA_ycJBcbp4hgbvO21HqX0_jnbRDnpa8fBEm2=GRn++Azw@mail.gmail.com> <CA+renyWW_wjY7Qsis6fHJL_VQj=274aRD2Tb-k_QYe=aNwEing@mail.gmail.com> <88ec1892-2282-ab67-b2aa-1f69003e2392@gmail.com> <a726ab6a-d814-7623-4b26-9300d0a1dfb4@illuminatedcomputing.com> <20110.1582665236@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox