SQL Window Functions: Performance, EXPLAIN, and Dialect Notes/Be explicit about NULL ordering when needed
Different engines may sort NULLs differently.
Section: Dialect notes
Be explicit about NULL ordering when needed
sql
sql
SELECT *,
ROW_NUMBER() OVER (
ORDER BY completed_at NULLS LAST, id
) AS rn
FROM tasks;Explanation
Explicit NULL ordering can preserve predictable ranking and lead/lag behavior across dialects that support it.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Dialect notes
QUALIFY shortcut in some warehouses
Filter window results without wrapping a subquery.
Portable alternative to QUALIFY
Use a subquery or CTE for broad compatibility.
Remember LAST_VALUE frame semantics
Default frames can make LAST_VALUE look broken.
Create a supporting index for partition/order keys
Help the database read rows in the right order.