{"record":{"id":"4b15a0d5fa868119","repo":"cube-js/cube","slug":"sql-parsing-error-this-errors-map-msg-colum","errorCode":null,"errorMessage":"SQL Parsing Error:\n${this.errors.map(({ msg, column, line }) => `${line}:${column} ${msg}`).join('\\n')}","messagePattern":"SQL Parsing Error:\n(.+?)\\) => `(.+?):(.+?) (.+?)`\\)\\.join\\('\\\\n'\\)\\}","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/parser/SqlParser.ts","lineNumber":170,"sourceCode":"    lexer.addErrorListener(new ExprErrorListener());\n\n    const parser = new GenericSqlParser(\n      new CommonTokenStream(lexer)\n    );\n    parser.buildParseTrees = true;\n    parser.removeErrorListeners();\n    parser.addErrorListener(new ExprErrorListener());\n\n    return parser.statement();\n  }\n\n  public canParse() {\n    return !this.errors.length;\n  }\n\n  public throwErrorsIfAny() {\n    if (this.errors.length) {\n      throw new UserError(\n        `SQL Parsing Error:\\n${this.errors.map(({ msg, column, line }) => `${line}:${column} ${msg}`).join('\\n')}`\n      );\n    }\n  }\n\n  public isSimpleAsteriskQuery(): boolean {\n    if (!this.canParse()) {\n      return false;\n    }\n\n    let result = false;\n\n    this.ast.accept(nodeVisitor({\n      visitNode(ctx) {\n        if (ctx instanceof QueryContext) {\n          const selectItems = ctx.getTypedRuleContext(SelectFieldsContext, 0);\n          if (selectItems && selectItems.getText() === '*') {\n            result = true;","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/parser/SqlParser.ts#L152-L188","documentation":"Aggregated parse-error report thrown by SqlParser.throwErrorsIfAny(). After ANTLR parsing of the SQL statement, all lexer/parser syntax errors are raised together as a UserError with 'line:column msg' lines. Callers like extractWhereConditions and extractTableFrom invoke it, so any SQL passed to these helpers must be parseable by the embedded GenericSql grammar.","triggerScenarios":"Calling SqlParser-based helpers (extractWhereConditions, extractTableFrom) with SQL that the ANTLR GenericSqlLexer/GenericSqlParser cannot parse — unsupported dialect constructs, missing FROM clauses, odd operators, or truncated statements.","commonSituations":"Cube Security Context / query rewrite features inspecting user SQL: dialect-specific functions (ILIKE, :: casts, ::type, LIMIT syntax variants), semicolon-terminated multi-statements, or vendor syntax the generic grammar rejects.","solutions":["Read each line:column entry and fix or simplify the SQL at those positions","Rewrite dialect-specific syntax to ANSI SQL (e.g. LOWER(a)=LOWER(b) instead of ILIKE, CAST(x AS t) instead of x::t)","Remove trailing semicolons and extra statements; pass a single statement","Test the query with isSimpleAsteriskQuery()/canParse() and fall back gracefully when it cannot parse"],"exampleFix":"// before\nextractTableFrom(\"SELECT * FROM t WHERE a::text = 'x'\")\n// after\nextractTableFrom(\"SELECT * FROM t WHERE CAST(a AS TEXT) = 'x'\")","handlingStrategy":"try-catch","validationCode":"const parser = new SqlParser(sql);\nif (!parser.canParse()) {\n  throw new Error('SQL not parseable by Cube generic SQL grammar: ' + sql);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const table = extractTableFrom(sql);\n} catch (e) {\n  if (e instanceof UserError && e.message.startsWith('SQL Parsing Error:')) {\n    console.error(e.message); // line:column per error\n    // fall back: skip rewrite or ask user to simplify query\n  } else { throw e; }\n}","preventionTips":["Use ANSI-compatible single-statement SQL without trailing semicolons","Replace dialect-specific syntax (::casts, ILIKE, vendor functions) before introspection","Call canParse()/isSimpleAsteriskQuery() first and degrade gracefully","Fix errors in the order listed — each line:column points at the offending token"],"tags":["sql","parsing","syntax-error","schema-compiler"],"backgroundTag":"sql-syntax-error","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}