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

Error if trying to parse 'LEFT JOIN dimension_soc_246_node_6 FOR SYSTEM_TIME AS OF PROCTIME() AS node_6' #1865

Closed wushuwu closed 4 months ago

wushuwu commented 4 months ago

Describe the bug

{"message":"Expected \"#\", \"--\", \"/*\", \"UPDATE\", or [ \\t\\n\\r] but \"S\" found.","expected":[{"type":"class","parts":[" ","\t","\n","\r"],"inverted":false,"ignoreCase":false},{"type":"literal","text":"/*","ignoreCase":false},{"type":"literal","text":"--","ignoreCase":false},{"type":"literal","text":"#","ignoreCase":false},{"type":"literal","text":"UPDATE","ignoreCase":true},{"type":"class","parts":[" ","\t","\n","\r"],"inverted":false,"ignoreCase":false},{"type":"literal","text":"/*","ignoreCase":false},{"type":"literal","text":"--","ignoreCase":false},{"type":"literal","text":"#","ignoreCase":false},{"type":"literal","text":"UPDATE","ignoreCase":true}],"found":"S","location":{"start":{"offset":526,"line":16,"column":40},"end":{"offset":527,"line":16,"column":41}},"name":"SyntaxError"} Database Engine SQL Server.

Using code

import { Parser } from 'node-sql-parser';
const parser = new Parser();
const processSqlValue = `
SELECT
  node_1.cnt AS cnt,
  node_6.wua_server_env_raw AS wua_server_env_raw
FROM
  view_soc_246_node_1 AS node_1
LEFT JOIN dimension_soc_246_node_6 FOR SYSTEM_TIME AS OF PROCTIME() AS node_6
ON node_1.id = node_6.wua_server_env_raw;
`
const ast = parser.astify(processSqlValue);
taozhi8833998 commented 4 months ago

temporal table

wushuwu commented 4 months ago

An error also occurred while parsing 'map[]' and 'json_object'.

import { Parser } from 'node-sql-parser';
const parser = new Parser();
const sql = `
  insert into sink_soc_10086_node_11(
    pk
    , f1
    )
    select
    CAST(map[uri,uri] as VARCHAR) 
    , uri
    from view_soc_10086_node_8
    ;
`
const ast = parser.astify(sql, {
  database: 'flinksql'
});
import { Parser } from 'node-sql-parser';
const parser = new Parser();
const sql = `
  select name, eventTime, eventDetail
  from (
      select
      concat('AK泄露告警') as name,
      cast(event_time as varchar) as eventTime,
      json_object(
          'risk-tag' value risk_tag,
          'user-agent' value user_agent,
      ) as eventDetail
  from check_risk
  )
  ;
`
const ast = parser.astify(sql, {
  database: 'flinksql'
});
taozhi8833998 commented 4 months ago

@wushuwu Please open a new issue, and follow the issue template.