是否有某个地方或任何配置选项可以让我强制 postgres 在每个使用 DESC 排序的查询上使用 NULLS LAST?
我不想在我的应用程序中将所有查询从 Criteria API 重写到 JPQL,而且 JPA Criteria API 似乎不允许设置空值最后一个选项。
最佳答案
没有。至少我从来没有听说过这样的。简单的检查也不会给它带来希望:
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也没有提到这样的全局开关,只是:
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.
关于Postgresql order by desc nulls last on every query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45029616/