oguimbal / pgsql-ast-parser

Yet another simple Postgres SQL parser
304 stars 43 forks source link

Doesn't parse trim function #141

Open onutosora opened 1 year ago

onutosora commented 1 year ago

Trying to parse a simple query that contains TRIM function.

SELECT trim(BOTH 'xyz' FROM 'yxTomxx');

Got an error:

Unexpected kw_both token: "both". Instead, I was expecting to see one of the following:

    - A "kw_all" token
    - A "kw_distinct" token
    - A "int" token
    - A "kw_order" token
    - A "rparen" token
    - A "star" token
    - A "kw_with" token
    - A "lparen" token
    - A "kw_select" token
    - A "word" token
    - A "kw_with" token
    - A "kw_not" token
    - A "word" token
    - A "op_plus" token
    - A "op_minus" token
    - A "kw_cast" token
    - A "kw_current_schema" token
    - A "kw_current_schema" token
    - A "kw_true" token
    - A "kw_false" token
    - A "kw_null" token
    - A "qparam" token
    - A "kw_default" token
    - A "word" token
    - A "word" token
    - A "word" token
    - A "word" token
    - A "kw_precision" token
    - A "kw_array" token
    - A "kw_array" token
    - A "kw_case" token
    - A "kw_primary" token
    - A "kw_unique" token
    - A "quoted_word" token
    - A "word" token
    - A "float" token
    - A "kw_current_catalog" token
    - A "kw_current_date" token
    - A "kw_current_role" token
    - A "kw_current_schema" token
    - A "kw_current_timestamp" token
    - A "kw_current_time" token
    - A "kw_localtimestamp" token
    - A "kw_localtime" token
    - A "kw_session_user" token
    - A "kw_user" token
    - A "kw_current_user" token
    - A "string" token
    - A "eString" token
    - A "kw_any" token
    - A "kw_some" token
    - A "kw_all" token

    at Parser.feed (...\node_modules\nearley\lib\nearley.js:343:27)
    at _parse (...\node_modules\pgsql-ast-parser\index.js:1911:16)
    at doParse (...\node_modules\pgsql-ast-parser\index.js:1866:27)
    at parse (...\node_modules\pgsql-ast-parser\index.js:1869:11) {
  offset: 3,
  token: {
    type: 'kw_both',
    value: 'both',
    text: 'BOTH',
    toString: [Function: tokenToString],
    offset: 12,
    lineBreaks: 0,
    line: 1,
    col: 13
  }
}

The same behavior occurs when using LEADING or TRAILING instead BOTH.