From: | "Arjan Saly Consultancy (EU)" <consultancy(at)arjansaly(dot)eu> |
---|---|
To: | Loles <lolesft(at)gmail(dot)com> |
Cc: | "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>, M Sarwar <sarwarmd02(at)outlook(dot)com> |
Subject: | Re: ORDER BY DESC and NULLS LAST by default |
Date: | 2023-10-27 14:42:48 |
Message-ID: | 31B4CC5A-ADE1-42C9-8A89-8B1EC78D8571@arjansaly.eu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
You should be able to use the ORDER BY <sort_espression> ASC NULLS LAST clause, see this page in the manuals: https://www.postgresql.org/docs/current/queries-order.html
However, if this doesn't work well, you might check your localisation and collation settings as the way a database sorts depends on these settings. They can be changed on OS level, in the database configuration and on session level, but you can also use the COLLATE statement in your query. I would expect PostgreSQL to override these settings when the ORDER BY …. NULL LAST (or FIRST) clause is used, but since I’ve never used this option, I can’t tell for sure. I have seen on other applications (not postgres) that if OS localisation or collation does not match the applications localisation/collation, things may get messed up. Mostly with special characters, but sometimes with sorting as well. To my experience this seems to be more of an issue on Windows machines than on Linux based machines.
See https://www.postgresql.org/docs/current/locale.html#LOCALE-BEHAVIOR for more information on localisation and collation in PostgreSQL.
Hope this helps!
Kind Regards,
Arjan Saly
Database & Business Intelligence Specialist
Arjan Saly Consultancy
e: consultancy(at)arjansaly(dot)eu
l: https://nl.linkedin.com/in/arjansaly
w: https://www.arjansaly.eu/consultancy

> Op 27 okt 2023, om 16:17 heeft M Sarwar <sarwarmd02(at)outlook(dot)com> het volgende geschreven:
>
> I do not think that this is available in any of the databases.
> Sarwar
>
> From: Loles <lolesft(at)gmail(dot)com>
> Sent: Friday, October 27, 2023 10:16 AM
> To: pgsql-admin(at)postgresql(dot)org <pgsql-admin(at)postgresql(dot)org>
> Subject: ORDER BY DESC and NULLS LAST by default
>
> Hi!
>
> Can the server be configured so that the default ORDER BY option is DESC instead of ASC?
>
> And to make it NULLS LAST instead of NULLS FIRST?
>
> Happy weekend and Thank you very much!
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2023-10-27 14:45:02 | Re: Rollback after "Connection timed out"? |
Previous Message | Ron | 2023-10-27 14:40:43 | Rollback after "Connection timed out"? |