Skip to content

Resolve a bare column inside a built-in function through the default columns - #2926

Merged
mathiasrw merged 18 commits into
fix/2916from
fix/2917
Nov 19, 2026
Merged

mathiasrw merged 18 commits into
fix/2916from
fix/2917

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Closes #2615 and #2917 (the same bug, reported twice). In a query over several tables, a bare column given to a built-in function such as UPPER, LENGTH or ROUND was read from the first table of FROM, so SELECT p.id, uname FROM p, q WHERE UPPER(uname) = "ANN" found nothing while uname = "ANN" found the rows. The compile-time branch of FuncValue.toJS passed its arguments context and tableid but not defcols, the map that resolves a bare column to its table; the other two branches (alasql.stdfn and user functions) already passed it. Now all three do.

With that, the alias walker of the comma-join filter (#2918) places a bare column inside a function, a CASE or an IN list like any other, so UPPER(uname) = "ANN" filters q before the join instead of waiting in WHERE.

Tests in test/test2917.js: the comma join and the explicit JOIN of the report, functions in SELECT and ORDER BY, a function inside a function and a user function, the filter on the compiled sources, CASE and an IN list over a bare column, both cases of #2615 (a joined table and a joined subquery), and an ambiguous bare column inside a function still throwing as outside. Suite 2537 pass, 213 skip, 0 fail (an earlier run showed test2149's CLI version check failing, which was a dist built with bun build.js alone, without the version injection that yarn build-only adds).

Branched off fix/2916 and into it, since the walker change builds on #2918.

mathiasrw and others added 3 commits October 29, 2026 20:24
…lose #2877 and close #2791 (#2683)

Since DEFAULT can be used as a name, `UPDATE t SET a = DEFAULT` and
`INSERT INTO t VALUES (DEFAULT, ...)` read it as a column named
`default`. UPDATE wrote undefined and INSERT threw a TypeError.

The grammar now reads DEFAULT on its own in SET and in VALUES as a
DefaultValue node. UPDATE writes the column default (NULL when the column
has none), and INSERT leaves the column out so the table default fills it.
A quoted [default] is still a column.
@mathiasrw
mathiasrw added this pull request to stack #2927 October 29, 2026 09:31
mathiasrw and others added 5 commits October 29, 2026 21:06
A correlated IN, NOT IN, ALL/ANY/SOME or EXISTS subquery in HAVING got the
group row as its outer scope, so t1.a read from an undefined t1 and threw.
These subqueries now get the group's source row, keyed by table alias, the
same way a scalar subquery in HAVING already does. WHERE is unchanged.
Add INSERT ... SET, expression default, IDENTITY and NOT NULL test case as suggested in #2921.
@mathiasrw mathiasrw added this to the v4.x Focus milestone Nov 9, 2026
@mathiasrw
mathiasrw merged commit 8b003d2 into main Nov 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants