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
818 stars 181 forks source link

Typescript type for Select.distinct does not match runtime value when parsing Snowflake SQL #2220

Open chris-codaio opened 6 days ago

chris-codaio commented 6 days ago

Describe the bug Typescript type for Select.distinct does not match runtime value when parsing Snowflake SQL.

Database Engine Snowflake

To Reproduce node-sql-parser version: 5.3.4 node version: 22.11.0

parser.astify('SELECT * from foo;', {database: 'Snowflake'});

[
  {
    with: null,
    type: 'select',
    options: null,
    distinct: { type: null },
    columns: [ [Object] ],
    into: { position: null },
    from: [ [Object] ],
    where: null,
    groupby: null,
    having: null,
    qualify: null,
    orderby: null,
    top: null,
    limit: { seperator: '', value: [] },
    window: null
  }
]

Expected behavior Declared type as follows. Note that distinct should be the string DISTINCT or null, but is {type: null} at runtime.

export interface Select {
  with: With[] | null;
  type: "select";
  options: any[] | null;
  distinct: "DISTINCT" | null;
  columns: any[] | Column[];
  from: From[] | TableExpr | null ;
  where: Binary | Function | null;
  groupby: { columns: ColumnRef[] | null, modifiers: ValueExpr<string>[] };
  having: any[] | null;
  orderby: OrderBy[] | null;
  limit: Limit | null;
  window?: WindowExpr;
  qualify?: any[] | null;
  _orderby?: OrderBy[] | null;
  _limit?: Limit | null;
  parentheses_symbol?: boolean;
  _parentheses?: boolean;
  loc?: LocationRange;
  _next?: Select;
  set_op?: string;
}

As a side note, there are some other mismatched/broken types in here. Examples include: