> 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
> 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
In response to
pgsql-hackers by date
|Next:||From: Jeff MacDonald <email@example.com>||Date: 2000-01-27 18:43:22|
|Subject: Spinlock error|
|Previous:||From: The Hermit Hacker||Date: 2000-01-27 18:05:00|
|Subject: Re: [HACKERS] CVS problem|
pgsql-sql by date
|Next:||From: Mark Wilson||Date: 2000-01-27 20:32:39|
|Subject: transaction aborted|
|Previous:||From: moreno||Date: 2000-01-27 18:20:33|
|Subject: Someone can help please? SELECT problems|