Re: Weird query sort

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Weird query sort
Дата
Msg-id 4187.1230422916@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Weird query sort  ("Jeffrey Melloy" <jmelloy@gmail.com>)
Список pgsql-general
"Jeffrey Melloy" <jmelloy@gmail.com> writes:
> It seems like I should be able to order by quer_time desc and then
> query_time asc. Am I missing something?

You'd have to do it *after* the join and GROUP BY if you want it to
control the input to the aggregate reliably.  Either of those operations
will feel free to output rows in whatever order suits its convenience.
Ordering in the sub-select is useful in connection with making sure its
LIMIT produces the tuples you want, but it isn't going to be preserved
through the join and GROUP BY.

Also, I think what you really need here is to have the intermediate
query "ORDER BY queries.query_id, query_time"; otherwise you risk
having the GROUP BY do a sort by query_id, which'll destroy the desired
ordering on query_time within query_id groups.

            regards, tom lane

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

Предыдущее
От: "Jeffrey Melloy"
Дата:
Сообщение: Weird query sort
Следующее
От: plu tard
Дата:
Сообщение: Finding foreign keys that are missing indexes