4

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.

1
  • 1
    You can work around not being able to sort nulls by using something like ORDER BY (column IS NULL), column DESC. false comes first in ASC order so by default nulls will be last. I don't know about configuration tho. Commented Jul 11, 2017 at 9:44

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.