Skip to content
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

Support for 'is null' in 'order by' (#3667) #4720

Merged
merged 7 commits into from
Oct 10, 2021

Conversation

OlivierCavadenti
Copy link
Collaborator

@OlivierCavadenti OlivierCavadenti commented Oct 10, 2021

  • Attempt to resolve issue Support for 'is null' in 'order by' #3667
  • add support to order nulls in order by with 'first' and 'last' option.
  • 'first' add 'is not null' in order by clause (=> put nulls in first position)
  • 'last' add 'is null' in order by clause (=> put nulls in last position)

table.increments('id').primary();
table.string('null_col').nullable().defaultTo(null);
})
.then(function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please rewrite this to use async/await?

@kibertoad
Copy link
Collaborator

TS types need to be updated, and we also need documentation updated for this.

@OlivierCavadenti
Copy link
Collaborator Author

TS types need to be updated, and we also need documentation updated for this.

I update index.d.ts and rework a test but it seems 'is null' is not valid in mssql:

RequestError: select [id] from [OrderByNullTest] order by ([null_col] is not null) asc - Incorrect syntax near the keyword 'is'.

I need to investigate

@kibertoad
Copy link
Collaborator

@OlivierCavadenti It appears that MSSQL doesn't support that, and one would need to implement hacks to get that working: https://stackoverflow.com/questions/5886857/sql-server-order-by-date-and-nulls-last

If you feel like implementing custom solution to get that working with MSSQL, that would be great, but if that's too much work, throwing an error when trying to use that param on MSSQL is also sufficient.

@OlivierCavadenti
Copy link
Collaborator Author

@OlivierCavadenti It appears that MSSQL doesn't support that, and one would need to implement hacks to get that working: https://stackoverflow.com/questions/5886857/sql-server-order-by-date-and-nulls-last

If you feel like implementing custom solution to get that working with MSSQL, that would be great, but if that's too much work, throwing an error when trying to use that param on MSSQL is also sufficient.

I will see what I can do to get that working with MSSQL. Thanks for the link.

@kibertoad
Copy link
Collaborator

Thanks a lot! Can you also add documentation for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants