Allow sorting by NULLS FIRST / NULLS LAST
See original GitHub issueProblem
Currently can’t seem to specify how to sort nulls in a findMany
Suggested solution
To be able to specify NULLS FIRST or NULLS LAST
Alternatives
Currently making separate queries and concat-ing them in JS
Additional context
On a table with rows that contain data synced from elsewhere, there’s a date field for last_synced_details_at
;
The column’s default value is null
(never been synced)
When attempting to get the “most stale rows” would be orderBy: { last_synced_details_at: "asc" }
, I’d get the ones that have been synced first, and rows that have never been synced after
Issue Analytics
- State:
- Created 3 years ago
- Reactions:103
- Comments:23 (3 by maintainers)
Top Results From Across the Web
How ORDER BY and NULL Work Together in SQL
If you apply the ORDER BY clause to a column with NULLs, the NULL values will be placed either first or last in...
Read more >SQL how to make null values come last when sorting ascending
Depending on the database engine, use ORDER BY expr some_column DESC NULLS LAST (Oracle) , ORDER BY ISNULL(some_column, 1), some_column ASC (MSSQL) or...
Read more >How to Order NULL Values First or Last in MySQL? - Designcise
Ordering NULL values last whilst sorting all non-NULL values first in an ascending order;; Ordering NULL values first followed by non-NULL ...
Read more >Simulate NULLS FIRST and NULLS LAST in the ORDER BY ...
When your query contains the ORDER BY clause to sort the result set, alphanumeric NULL data will sort to the bottom if the...
Read more >How to ORDER BY with NULLS comes FIRST or LAST - Help
You can check for IS NULL in the ORDER BY clause. Nulls first: select name from people order by name asc. Nulls last:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All right, let’s try 💪
Let’s consider
tabletosort
:PostgreSQL
ASC
DESC
MySQL
ASC
DESC
SQLite
ASC
DESC
Microsoft SQL Server
ASC
DESC
Summary
asc
desc
Proposal
Like this, there is NO change of the current behavior and you can opt-in a specific sorting.
🤞 that the topic can move forward 🥳 //BTW, I 🧡 prisma.
Hey folks,
This feature was released as part of the 4.1.0 version.
Thanks for upvoting this feature. If you wanna give any feedback, please comment on this issue https://github.com/prisma/prisma/issues/14377
Cheers 👋