Skip to content

fix: keep brackets around keyword column names in toString() - #3074

Open
abhi478jeetur-rgb wants to merge 3 commits into
AlaSQL:developfrom
abhi478jeetur-rgb:fix/tostring-keyword-column-brackets
Open

abhi478jeetur-rgb wants to merge 3 commits into
AlaSQL:developfrom
abhi478jeetur-rgb:fix/tostring-keyword-column-brackets

Conversation

@abhi478jeetur-rgb

Copy link
Copy Markdown
Contributor

What this PR does

Column.needsBrackets only checked for spaces, dots, dashes and brackets, so toString() printed a column name that is a keyword — e.g. [value] or [select] — without brackets. The printed SQL then parsed as something else ([value]->a lost its result: [{id:1}] instead of [{id:1,x:5}]) or did not parse at all (SELECT [select]->a AS x FROM ?).

needsBrackets now also brackets a name the lexer reads as a keyword: it asks the parser's own lexer whether the name tokenizes as a plain identifier (LITERAL) and caches the answer per name, so the check always agrees with the grammar and needs no separate keyword list. Non-keyword names (id, user, ...) still print bare.

Tests

New test/test3073.js (5 tests) — each case parses, prints with toString(), parses again and compares the results, covering keyword column names in the select list, in ->, in WHERE and in ORDER BY, as suggested in the issue. The issue's two examples are reproduced verbatim. Before the fix 4 of the 5 tests failed; after the fix all 5 pass.

Full test suite (sh build.sh && bun test): 2638 passed, 213 skipped, 0 failed (2851 tests, 693 files). Prettier check clean.

Fixes #3073

Column.needsBrackets only checked for spaces, dots, dashes and
brackets, so toString() printed a keyword column name like [value]
or [select] bare. The printed SQL then parsed as something else
([value]->a lost its result) or did not parse at all
(SELECT [select]->a).

Also bracket a name the lexer reads as a keyword: ask the parser's
own lexer whether the name tokenizes as LITERAL, and cache the
answer per name. Non-keyword names (id, user, ...) still print bare.

Fixes AlaSQL#3073
@mathiasrw mathiasrw added this to the v5.0.0 milestone Nov 17, 2026
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.

toString() drops the brackets around a column name that is a keyword

2 participants