You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sort NULL and mixed values in ORDER BY as SQLite, and honour NULLS FIRST and NULLS LAST, with a dialect keeping the old order #3172
After #3165 and #2693 the ORDER BY comparator still uses the rules of compileOrder (src/select/orderby.js). It compares (a[key]||''), so NULL, undefined, 0 and '' all count as '' and sort between negative and positive numbers. .valueOf() is added only for columns declared DATE, DATETIME, DATETIME2, STRING or NUMBER, so a column of numbers and text has no defined order.
alasql('CREATE TABLE p (n INT); INSERT INTO p VALUES (2), (NULL), (-1), (0)');alasql('SELECT COLUMN n FROM p ORDER BY n');// [-1, null, 0, 2] SQLite: [null, -1, 0, 2]
With nullOrder: 'v4' the comparator keeps today's (a||'') rules. Add it to alasql/dialect/v4.
Keep the sort stable.
COLLATE NOCASE applies only to text.
What stays the same
Clean numbers or clean text without NULLs sort as before.
With alasql/dialect/v4 every ORDER BY gives the 4.x order.
In the default, the place of NULL, undefined, 0 and '' changes, and so does the order of mixed columns, also in GROUP_CONCAT(... ORDER BY ...) and set operations.
Done when
A new test file named after this issue covers the example above in both directions, the mixed column 2, NULL, 0, missing, -1, 'b', '10' (SQLite gives [null, null, -1, 0, 2, '10', 'b']), NULLS FIRST and NULLS LAST with and without a direction, dates in an undeclared column, and the same queries with alasql/dialect/v4.
The ORDER BY matrix in the dialect test against SQLite covers NULL, mixed types and NULLS FIRST and NULLS LAST, and their expected differences are removed.
The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.
Activity