Re: Reproducing incorrect order with order by in a subquery

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Reproducing incorrect order with order by in a subquery
Дата
Msg-id dd2f192c-2b90-2bb7-27b4-004af7e7e26a@gmx.net
обсуждение исходный текст
Ответ на Reproducing incorrect order with order by in a subquery  (Ruslan Zakirov <ruslan.zakirov@gmail.com>)
Ответы Re: Reproducing incorrect order with order by in a subquery
Список pgsql-general
Ruslan Zakirov schrieb am 13.06.2023 um 09:49:
> For example I have a query:
>
> SELECT main.*, count(*) OVER () FROM (SELECT DISTINCT ... ORDER BY X)
> main;
>
> So the `ORDER BY` clause ended up in a subquery. Most of the time
> ordering works until it doesn't.
>
> Can you help me create a set of test tables with some data to
> reproduce this problem more repeatedly? I just want to write a
> regression test to make sure it doesn't happen again.
Your final/overall query has no ORDER BY, so Postgres is free to return the result in any order it likes.

You will have to add an ORDER BY to the "main" part to get a guaranteed sort order





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

Предыдущее
От: rihad
Дата:
Сообщение: Re: pg_upgrade v15 not generating analyze_new_cluster.sh
Следующее
От: Francisco Olarte
Дата:
Сообщение: Re: [Beginner Question] Will the backup wal file take too much storage space?