ORDER BY and DISTINCT ON

Поиск
Список
Период
Сортировка
От Neil Conway
Тема ORDER BY and DISTINCT ON
Дата
Msg-id 87ad5xppw7.fsf@mailbox.samurai.com
обсуждение исходный текст
Ответы Re: ORDER BY and DISTINCT ON  (Bruno Wolff III <bruno@wolff.to>)
Re: ORDER BY and DISTINCT ON  (Greg Stark <gsstark@mit.edu>)
Список pgsql-hackers
We reject the following query:

nconway=# create table abc (a int, b int, c int);
CREATE TABLE
nconway=# select distinct on (a) a, b, c from abc order by b, c, a;
ERROR:  SELECT DISTINCT ON expressions must match initial ORDER BY
expressions

This works fine, of course:

nconway=# select distinct on (a) a, b, c from abc order by a, b, c;a | b | c 
---+---+---
(0 rows)

src/backend/parser/parse_clause.c notes:
    /*     * If the user writes both DISTINCT ON and ORDER BY, then the     * two expression lists must match (until
oneor the other     * runs out).  Otherwise the ORDER BY requires a different     * sort order than the DISTINCT does,
andwe can't implement     * that with only one sort pass (and if we do two passes, the     * results will be rather
unpredictable).However, it's OK to     * have more DISTINCT ON expressions than ORDER BY     * expressions; we can just
addthe extra DISTINCT values to     * the sort list, much as we did above for ordinary DISTINCT     * fields.     *
*Actually, it'd be OK for the common prefixes of the two     * lists to match in any order, but implementing that check
   * seems like more trouble than it's worth.     */
 

Does this strike anyone else as being wrong?

-Neil



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

Предыдущее
От: markw@osdl.org
Дата:
Сообщение: Re: more dbt-2 results hyperthreading on linux-2.6.0-test11
Следующее
От: Kurt Roeckx
Дата:
Сообщение: Walker/mutator prototype.