postgresql `orderBy()` does not properly utilize NULLS third argument
See original GitHub issueEnvironment
Knex version: 0.95.14 Database + version: postgres 14.0
Bug
-
The orderBy() command in postgres does not function properly for postgres. Currently, the command
orderBy('field', 'desc', 'first')
compiles toORDER BY ("field" is NULL) desc
but in postgres it needs to beORDER BY "field" desc NULLS LAST
. -
Example generating incorrect order strings - https://runkit.com/embed/k2t79bssiic7
-
Documentation for the proper postgres syntax is at https://www.postgresql.org/docs/14/queries-order.html .
I’d be happy to attempt to fix the problem if someone could point me to the right files in the code that modified this behavior. I looked around the code but couldn’t find an obvious place in the https://github.com/knex/knex/blob/master/lib/dialects/postgres/query/pg-querycompiler.js where it would go.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top GitHub Comments
Yes, if you put the function with the same name, like in mssql-querycompiler, knex will use it.
Please see the test with name ‘order by with null’ in selects.spec.js (line 562). I made an integration test but if you have the bug, maybe it’s not good enough.
For unit test, see in builder.js (in test/unit/query), line 5748 (first test is ‘order by, null first’).
Released in 1.0.2