← Winnitude! Search  ·  Reader Mode (1289 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 7 LINKS

Broken parse/stringify for IS [NOT] TRUE/FALSE/UNKNOWN, ROW(...), XOR, index hints, and quoted aliases without AS · Issue #66 · JavaScriptor/js-sql-parser

Repository navigation

Broken parse/stringify for IS [NOT] TRUE/FALSE/UNKNOWN, ROW(...), XOR, index hints, and quoted aliases without AS  #66


New issue

New issue

Open

Open
Broken parse/stringify for IS [NOT] TRUE/FALSE/UNKNOWN, ROW(...), XOR, index hints, and quoted aliases without AS #66

Description

@trackoor's profile trackoor opened on Nov 16, 2026

Several MySQL SELECT constructs that have grammar and stringify rules in js-sql-parser either stringify into invalid SQL (IN [object Object], ROW (()) or throw an uncaught TypeError / ReferenceError.

Reproduction (npm i js-sql-parser@1.6.0 && node repro.js):

const parser = require("js-sql-parser");

const queries = [
  "SELECT a IS TRUE FROM t",
  "SELECT a IS NOT UNKNOWN FROM t",
  "SELECT ROW(a, b) = ROW(1, 2) FROM t",
  "SELECT a XOR b FROM t",
  "SELECT a FROM t USE INDEX (idx)",
  "SELECT a \"alias\" FROM t",
];

for (const sql of queries) {
  try {
    const ast = parser.parse(sql);
    console.log(sql, "->", JSON.stringify(parser.stringify(ast)));
  } catch (err) {
    console.log(sql, "->", err.constructor.name + ": " + err.message.split("\n")[0]);
  }
}

Actual output:

SELECT a IS TRUE FROM t -> " SELECT a IN [object Object] FROM t"
SELECT a IS NOT UNKNOWN FROM t -> " SELECT a IN NOT [object Object] FROM t"
SELECT ROW(a, b) = ROW(1, 2) FROM t -> " SELECT ROW (() = ROW (() FROM t"
SELECT a XOR b FROM t -> TypeError: Cannot read properties of undefined (reading 'toUpperCase')
SELECT a FROM t USE INDEX (idx) -> TypeError: Cannot read properties of undefined (reading 'call')
SELECT a "alias" FROM t -> ReferenceError: $01 is not defined

Expected: each query parses and stringify() returns valid SQL that parse() accepts (IS [NOT] TRUE/FALSE/UNKNOWN, ROW(a, b), XOR, USE/FORCE/IGNORE INDEX, and single- or double-quoted column aliases without AS).

In src/stringify.js and src/sqlParser.jison: travelIsExpression appends 'in' instead of 'is' and calls this.append(ast.right) instead of this.travel(ast.right); ROW '(' expr_list ')' stores value: $2 ('(') instead of $3; XORExpression omits operator: $2; IndexHintList does not match travelIndexList; and selectExprAliasOpt's | STRING action uses $2 instead of $1 (compiled by Jison to $$[$01]).

Versions: js-sql-parser@1.6.0 and master (6b4ef84, built with npm run build) on Node.js v26.13.0.

Credit: https://ucsbplse.github.io/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions