pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Julian Scarfe <jscarfe@callnetuk.com>
Cc: pgsql-hackers@postgreSQL.org, pgsql-sql <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] DISTINCT ON: speak now or forever hold your peace
Date: Thu, 27 Jan 2000 13:33:16 -0500
Message-ID: <5844.948997996@sss.pgh.pa.us> (raw)
In-Reply-To: <13995.948820606@sss.pgh.pa.us>
References: <B4B3546E.5A80%jscarfe@callnetuk.com>
	<13995.948820606@sss.pgh.pa.us>

I wrote:
> To fix this we need some kind of syntactic separator.  The cleanest
> idea that comes to my mind is to require parentheses around the ON
> target:
> 		SELECT DISTINCT ON (expression) target1, ...
> One immediate advantage of allowing an expression is that you can do
> distinct-on-two-fields in a rather klugy way, eg
> 		SELECT DISTINCT ON (field1 || ' ' || field2) ...
> We might someday extend it to allow multiple DISTINCT fields, eg,
> 		SELECT DISTINCT ON (expr1 [, expr2 ...]) target1, ...
> but I'm not promising to do that now (unless it's really easy ;-)).

FYI, I have committed this change.  It did turn out to be just as easy
to support multiple DISTINCT ON expressions, so 7.0 will accept
	SELECT DISTINCT ON (expr1 [, expr2 ...]) target1, ...

> What I'd prefer to do is put in an
> error check that says "if you use both DISTINCT ON and ORDER BY, then
> the DISTINCT ON expression must be the first ORDER BY item".

More generally, if you use both then the DISTINCT and ORDER lists must
match until one or the other runs out.

			regards, tom lane



view thread (36+ messages)  latest in thread

Message-ID: <5844.948997996@sss.pgh.pa.us>
Permalink:  ../5844.948997996@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5844.948997996@sss.pgh.pa.us

 · 

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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jscarfe@callnetuk.com
  Subject: Re: [SQL] DISTINCT ON: speak now or forever hold your peace
  In-Reply-To: <5844.948997996@sss.pgh.pa.us>
  References: <B4B3546E.5A80%jscarfe@callnetuk.com> <13995.948820606@sss.pgh.pa.us> <5844.948997996@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