-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postgresql orderBy()
does not properly utilize NULLS third argument
#4837
Comments
Check MSSQL specific syntax, it's the same idea :
Order by null syntax is created in _formatGroupsItemValue function and it need to be overrided like MSSQL. |
And please add integration test to test order of results in all DB. If we have the problem, it seems integration tests are not exhaustive. |
So if I add a function with the exact same name into the postgres-querycompiler I can expect the same input/output contract and would just need to make it spit out the postgres equivalent? For the unit tests where do I go to add the unit tests and bootstrap in the test data accordingly? Is there an good example in the repo I can use as a blueprint? |
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'). |
@owenallenaz say me if you need help for unit test. You can also push a PR and I will help you. |
Released in 1.0.2 |
Environment
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.
The text was updated successfully, but these errors were encountered: