Re: Clarify the ordering guarantees in combining queries (or lack thereof)

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Clarify the ordering guarantees in combining queries (or lack thereof)
Дата
Msg-id CAKFQuwbzdxypF0Gb9N-3eQsnrgy5r6pdWF2a6XnZWf9L2-EbYA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Clarify the ordering guarantees in combining queries (or lack thereof)  (Shay Rojansky <roji@roji.org>)
Список pgsql-docs
On Thursday, July 14, 2022, Shay Rojansky <roji@roji.org> wrote:

If there's a guarantee that UNION ALL preserves ordering - as Tom seems to indicate in the thread quoted above - then the above works. If there's no such guarantee, then AFAIK the above can't be rewritten; putting the ORDER BY outside - on the results of the UNION ALL - would order all results rather than preserving each resultset's ordering.


Yes, an order by outside the union will sort the union results as a whole.  You can still write an order by and the union all so you get any conceivable ordering, though it may possibly require putting the union into a subquery depending on the order and output column combination desired.

David J.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Clarify the ordering guarantees in combining queries (or lack thereof)
Следующее
От: PG Doc comments form
Дата:
Сообщение: pg_advisory_unlock(null)