Re: ORDER BY DESC and NULLS LAST by default

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx
l: https://nl.linkedin.com/in/arjansaly
w: https://www.arjansaly.eu/consultancy



Mail Signature.png

Op 27 okt 2023, om 16:17 heeft M Sarwar <sarwarmd02@xxxxxxxxxxx> het volgende geschreven:

I do not think that this is available in any of the databases.
Sarwar


From: Loles <lolesft@xxxxxxxxx>
Sent: Friday, October 27, 2023 10:16 AM
To: pgsql-admin@xxxxxxxxxxxxxx <pgsql-admin@xxxxxxxxxxxxxx>
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!


[Index of Archives]     [Postgresql Home]     [Postgresql General]     [Postgresql Performance]     [Postgresql PHP]     [Postgresql Jobs]     [PHP Users]     [PHP Databases]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Forum]

  Powered by Linux