taozhi8833998 / node-sql-parser

Parse simple SQL statements into an abstract syntax tree (AST) with the visited tableList and convert it back to SQL
https://taozhi8833998.github.io/node-sql-parser/
Apache License 2.0
780 stars 174 forks source link

Getting error while parsing a valid Postgres query having jsonb_to_recordset #1866

Closed KshitijBharde closed 4 months ago

KshitijBharde commented 4 months ago

Describe the bug Getting "peg$SyntaxError" error while parsing a valid Postgres query having jsonb_to_recordset

import { Parser as PostgresParser } from 'node-sql-parser/build/postgresql';
const parser = new PostgresParser();

parser.parse(`
SELECT
  *
from
  jsonb_to_recordset(
    '[{"amount":23, "currency": "INR"}]' :: jsonb
  ) as l_amount (amount decimal, currency text);
`);

Database Engine PostgreSQL

To Reproduce -the SQL that be parsed:

  SELECT
    *
  from
    jsonb_to_recordset(
      '[{"amount":23, "currency": "INR"}]' :: jsonb
    ) as l_amount (amount decimal, currency text);

-the node-sql-parser version: 4.18.0 -the node version: v20.8.0

Expected behavior This query has valid pg syntax, we should get a parsed AST for it.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Error: /Users/taozhi/Workspaces/OpenSources/node-sql-parser/pegjs/postgresql.pegjs:5121 return new peg$SyntaxError( ^ o [SyntaxError]: Expected ")", ",", "--", "/", or [ \t\n\r] but "d" found. at peg$buildStructuredError (/Users/taozhi/Workspaces/OpenSources/node-sql-parser/pegjs/postgresql.pegjs:5121:12) at Object.typeCase [as postgresql] (/Users/taozhi/Workspaces/OpenSources/node-sql-parser/pegjs/postgresql.pegjs:40189:11) at r.value (/Users/taozhi/Workspaces/OpenSources/node-sql-parser/src/parser.js:26:43) at Object. (/home/kshitij/work/project-ut/autozz_v2/packages/node-sdk/src/instrumentation/libraries/pg/mocks/temp.ts:4:8) at Module._compile (node:internal/modules/cjs/loader:1241:14) at Module.m._compile (/home/kshitij/.nvm/versions/node/v20.8.0/lib/node_modules/ts-node/src/index.ts:1618:23) at Module._extensions..js (node:internal/modules/cjs/loader:1295:10) at Object.require.extensions. [as .ts] (/home/kshitij/.nvm/versions/node/v20.8.0/lib/node_modules/ts-node/src/index.ts:1621:12) at Module.load (node:internal/modules/cjs/loader:1091:32) at Function.Module._load (node:internal/modules/cjs/loader:938:12) { expected: [ { type: 'class', parts: [Array], inverted: false, ignoreCase: false }, { type: 'literal', text: '/', ignoreCase: false }, { type: 'literal', text: '--', ignoreCase: false }, { type: 'literal', text: ',', ignoreCase: false }, { type: 'class', parts: [Array], inverted: false, ignoreCase: false }, { type: 'literal', text: '/*', ignoreCase: false }, { type: 'literal', text: '--', ignoreCase: false }, { type: 'literal', text: ')', ignoreCase: false } ], found: 'd', location: { start: { offset: 112, line: 6, column: 25 }, end: { offset: 113, line: 6, column: 26 } } }