Re: [SQL] DISTINCT ON: speak now or forever hold your peace

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] DISTINCT ON: speak now or forever hold your peace
Дата
Msg-id 5844.948997996@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [SQL] DISTINCT ON: speak now or forever hold your peace  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
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 acceptSELECT 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: moreno
Дата:
Сообщение: Someone can help please? SELECT problems
Следующее
От: Mark Wilson
Дата:
Сообщение: transaction aborted