pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Jungwirth <pj@illuminatedcomputing.com>
To: 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 13:00:40 -0800
Message-ID: <a726ab6a-d814-7623-4b26-9300d0a1dfb4@illuminatedcomputing.com> (raw)
In-Reply-To: <88ec1892-2282-ab67-b2aa-1f69003e2392@gmail.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>

On 2/25/20 11:46 AM, Stanislav Motycka wrote:
> 
> 
> Dňa 25. 2. 2020 o 20:28 Paul A Jungwirth napísal(a):
>> I take the proposal to mean this:
>>
>> SELECT listOfColumns [EXCEPT listOfColumns] FROM ...
> Exactly, simply exclude unneeded columns from the base clause "SELECT", 
> nothing more ..

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;

Believe it or not these are valid SQL:

SELECT;
SELECT EXCEPT SELECT;

This fails today but only because of the different number of columns:

SELECT 1 AS SELECT EXCEPT SELECT;

So the parser understands it as selectQuery EXCEPT selectQuery, but you 
can see how it could also be parsable as this new structure. So the 
parser would have to decide which is meant (if that's even possible at 
that early stage).

I guess as soon as you exclude two columns it is unambiguous though 
because of this comma: SELECT ... EXCEPT SELECT, .... And anyway I think 
for such a pathological case you could just tell people to add double 
quotes.

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. Also a few other notes (after very brief testing):

SELECT * EXCEPT (foo) FROM t;	-- works
SELECT * EXCEPT (foo, bar) FROM t;	-- works
SELECT t.* EXCEPT (foo) FROM t;	-- works
SELECT * EXCEPT foo FROM t;	-- fails
SELECT foo, bar EXCEPT (foo) FROM t;	-- fails
SELECT t1.foo, t2.* EXCEPT (foo) FROM t1 JOIN t2 ON ...; -- works
SELECT t2.*, t1.foo EXCEPT (foo) FROM t1 JOIN t2 ON ...; -- fails!

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).

Regards,

-- 
Paul              ~{:-)
pj@illuminatedcomputing.com





view thread (14+ messages)  latest in thread

Message-ID: <a726ab6a-d814-7623-4b26-9300d0a1dfb4@illuminatedcomputing.com>
Permalink:  ../a726ab6a-d814-7623-4b26-9300d0a1dfb4@illuminatedcomputing.com/
Also on:    postgresql.org/message-id/a726ab6a-d814-7623-4b26-9300d0a1dfb4@illuminatedcomputing.com

 · 

reply

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: pj@illuminatedcomputing.com, stanislav.motycka@gmail.com
  Subject: Re: a proposal for a new functionality: "SELECT * [EXCEPT col1 [,col2]]
  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>

* 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