jet icon indicating copy to clipboard operation
jet copied to clipboard

Support `[NULLS { FIRST | LAST }]` for `jet.OrderByClause`

Open oxer-0 opened this issue 1 year ago • 2 comments
trafficstars

Is your feature request related to a problem? Please describe. The type OrderByClause does not support optional [NULLS { FIRST | LAST }] (PostgreSQL) expression, Causing Nulls always being first when using descending ordering

SELECT * FROM tbl ORDER BY key DESC NULLS LAST

Same thing applies to MySQL/MariaDB, except they sort Null values first when using ascending ordering, and it has a different syntax for controlling it, and I was not able to find anything in the documents that explains about this behavior.

SELECT * FROM tbl ORDER BY -key ASC (notice the - before key)

Describe the solution you'd like Exposing methods (IMHO NullsFirst, NullsLast seem clear enough) for controlling where do nulls appear through OrderByClause could be helpful in lots of cases

oxer-0 avatar Dec 09 '23 15:12 oxer-0

Agree, make sense. :+1:

go-jet avatar Dec 10 '23 22:12 go-jet

As a workaround, you can check if key is null:

SELECT * 
FROM tbl 
ORDER BY key is null, key DESC

houtn11 avatar Dec 16 '23 16:12 houtn11

NULLS_FIRST/NULLS_LAST support added in Release v2.11.0.

go-jet avatar Feb 28 '24 13:02 go-jet