Repository navigation
Make GREATEST and LEAST return NULL consistently to close #2583 - #2735
vaibh14yadav-tech wants to merge 1 commit into
Conversation
|
@mathiasrw, |
|
We are currently preparing towards the v5.0.0 introducing a bunch of breaking changes - a lot of them about NULL - and a lot of them about the dialects of different engines. I hope it happens during next week. I will take your PR and get into the mix. The code structure will update and I am OK to to do the work adapting your PR. Thank you for putting time into AlaSQL. |
|
Thanks a lot, that's great to hear! Happy for you to adapt it however fits the v5 structure. One small request: if possible, could the change land through this PR (or keep my commit), or credit me as a co-author if it ends up in a different commit? It's part of a course contribution, so it would really help me show it. Thanks again, and good luck with the v5 release! |
Closes #2583
Problem
GREATEST/LEAST(and the scalarMAX(a, b)/MIN(a, b)) used a plainreducewitha > b ? a : b. Comparisons withundefined(SQLNULL) are always false andnullis coerced to0, so results depended on argument order and on whether the NULL was a SQLNULLor a JSnullparameter, e.g.GREATEST(1, NULL)→undefinedbutGREATEST(NULL, 1)→1.Fix
In
src/55functions.js, check for NULL (== null, covering bothnullandundefined) before comparing. If any argument is NULL the result is NULL; otherwise the existing>/<comparison is used unchanged, so numbers, strings and dates behave as before (avoiding the regression noted for #2479/#2480).NULL rule
I implemented the SQL-standard rule (NULL if any argument is NULL, as in SQL:2023, MySQL, Oracle and SQLite). I know the default is meant to be decided for v5 — happy to switch to the skip-NULLs rule (PostgreSQL / SQL Server / DuckDB) or put one behind an option if you prefer. Only the filter in the reduce and test D would change.
Tests
New
test/test2583.js:NULL)nullparameter is treated as NULL, not as0MAX/MINyarn test-only: 2446 pass, 0 fail.