Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql order by desc nulls last on every query

Is there a configuration option somewhere or anything that will allow me to force postgres to use NULLS LAST on every query that uses DESC ordering?

I dont want to rewrite all queries from Criteria API to JPQL in my app, and it seems JPA Criteria API does not allow setting nulls last option.

like image 835
Nadir Avatar asked Sep 14 '25 14:09

Nadir


1 Answers

No. At least I never heard of such. Simple check does not give hope for it either:

t=# select setting, name from pg_settings where name like '%null%';
 setting |         name
---------+-----------------------
 on      | array_nulls
 off     | transform_null_equals
(2 rows)

https://www.postgresql.org/docs/current/static/queries-order.html does not mention such global switches either, just:

The NULLS FIRST and NULLS LAST options can be used to determine whether nulls appear before or after non-null values in the sort ordering. By default, null values sort as if larger than any non-null value; that is, NULLS FIRST is the default for DESC order, and NULLS LAST otherwise.

like image 160
Vao Tsun Avatar answered Sep 17 '25 00:09

Vao Tsun