oguimbal / pgsql-ast-parser

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

Missing `[ OF table_name [, ...] ]` #164

Open youngkiu opened 5 months ago

youngkiu commented 5 months ago

https://www.postgresql.org/docs/12/sql-select.html

SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
    [ * | expression [ [ AS ] output_name ] [, ...] ]
    [ FROM from_item [, ...] ]
    [ WHERE condition ]
    [ GROUP BY grouping_element [, ...] ]
    [ HAVING condition ]
    [ WINDOW window_name AS ( window_definition ) [, ...] ]
    [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
    [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]
    [ LIMIT { count | ALL } ]
    [ OFFSET start [ ROW | ROWS ] ]
    [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
    [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ]

The [ OF table_name [, ...] ] part is missing below.

https://github.com/oguimbal/pgsql-ast-parser/blob/master/src/syntax/select.ne

select_statement
    -> select_what select_from:? select_where:? (select_groupby select_having:?):? select_order_by:? select_limit_offset:? (select_for select_skip:?):?
    {% x => {
        let [what, from, where, _groupBy, orderBy, limit, _selectFor] = x;
        from = unwrap(from);
        let groupBy = _groupBy && _groupBy[0];
        let having = _groupBy && _groupBy[1];
        groupBy = groupBy && (groupBy.length === 1 && groupBy[0].type === 'list' ? groupBy[0].expressions : groupBy);
        having = having && unwrap(having);
        let selectFor = _selectFor && _selectFor[0];
        let skip = _selectFor && _selectFor[1];
        skip = unwrap(skip);
        return track(x, {
            ...what,
            ...from ? { from: Array.isArray(from) ? from : [from] } : {},
            ...groupBy ? { groupBy } : {},
            ...having ? { having } : {},
            ...limit ? { limit: unwrap(limit) } : {},
            ...orderBy ? { orderBy } : {},
            ...where ? { where } : {},
            ...selectFor ? { for: selectFor[1] } : {},
            ...skip ? { skip } : {},
            type: 'select',
        });
    } %}