taozhi8833998 / taozhi8833998/node-sql-parser
Trailing comma not able to generate parser.astify throws error of invalid column clause where v4.7.0 it parse properly
@taozhi8833998 is already working on this.
Since Sep 7, 2026.
- Dominant language
- PEG.js
- Stars
- 1k
- Forks
- 244
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
parser.astify() throws Error: invalid column clause with select statement for a valid query that combines three things: (1) a trailing comma before FROM, (2) a FROM clause that is a comma-separated list of ≥2 sub-queries (derived tables), and (3) the last sub-query selects multiple columns.
This is a regression: the exact same query parsed successfully in v4.7.0 but fails in v5.4.0. After the trailing comma the parser still expects another SELECT column, and when the FROM list ends in a multi-column derived table it appears to mis-attribute those columns back to the outer SELECT column list, producing invalid column clause.
Database Engine
BigQuery (trailing commas before FROM are valid BigQuery syntax). Note: the error also reproduces with postgresql, transactsql, and mysql passed as the database option — it is not dialect-specific.
To Reproduce
- SQL being parsed (minimal):
SELECT a, FROM ( SELECT 1 ) x, ( SELECT c, d ) - SQL being parsed (real-world example, same shape — also throws):
SELECT inv.id, inv.item_nbr, FROM ( SELECT container_id AS id, item_nbr FROM receiving_item ) AS inv, ( SELECT delivery_number, doc_number FROM delivery_doc ) AS del WHERE inv.id = del.delivery_number - node-sql-parser version:
5.4.0(works correctly in4.7.0) - node version:
v24.11.0
Reproduction script:
const { Parser } = require('node-sql-parser');
const parser = new Parser();
const sql = "SELECT inv.id, inv.item_nbr, FROM ( SELECT container_id AS id, item_nbr FROM receiving_item ) AS inv, ( SELECT delivery_number, doc_number FROM delivery_doc ) AS del WHERE inv.id = del.delivery_number"
parser.astify(sql, { database: 'bigquery' });
// v5.4.0 → throws: "invalid column clause with select statement"
// v4.7.0 → parses successfully
All three conditions are required — removing any one makes v5.4.0 parse it fine:
| Query | v5.4.0 |
|---|---|
SELECT a, FROM ( SELECT 1 ) x, ( SELECT c, d ) |
❌ throws |
SELECT a FROM ( SELECT 1 ) x, ( SELECT c, d ) — no trailing comma |
✅ OK |
SELECT a, FROM ( SELECT c, d ) — single table |
✅ OK |
SELECT a, FROM ( SELECT 1 ) x, ( SELECT c ) — last sub-query has 1 column |
✅ OK |
Expected behavior
astify() should parse the query into an AST successfully (as it did in v4.7.0). A trailing comma before FROM is valid BigQuery syntax, and the statement is otherwise well-formed, so it should not raise invalid column clause with select statement.
Screenshots
Not applicable — console output:
Error: invalid column clause with select statement
at Parser.astify (.../node-sql-parser/...)
Additional context
- check out this code: https://stackblitz.com/edit/stackblitz-starters-m9anqzwg?file=index.js
- Regression introduced between 4.7.0 (works) and 5.4.0 (fails).
- Reproduces across
bigquery,postgresql,transactsql, andmysqldialect options — all throw the sameinvalid column clause with select statement. - Environment: node
v24.11.0, npm11.6.1, macOS. - Workaround: stripping the redundant trailing comma before
FROMprior toastify()restores 4.7.0 behavior across all dialects.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.