oguimbal / pgsql-ast-parser

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

An error occurs if the 'null | not null' property value does not exist. #121

Closed myyrakle closed 1 year ago

myyrakle commented 1 year ago

When parsing the following query, the library throws an error.

create table ext_chain
(
    id int8 primary key,
    chain_name varchar(100) not null,
    created_at  timestamptz not null,
    updated_at timestamptz not null,
    deleted_at timestamptz
);
/Users/myyrakle/Study/eojuk/dist/input/postgres.js:89
                    for (const nodeOfConstraints of nodeOfTable === null || nodeOfTable === void 0 ? void 0 : nodeOfTable.constraints) {
                                                                                                                          ^

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at PostgreSQLParser.parseTable (/Users/myyrakle/Study/eojuk/dist/input/postgres.js:89:123)
    at PostgreSQLParser.parse (/Users/myyrakle/Study/eojuk/dist/input/postgres.js:53:38)
    at /Users/myyrakle/Study/eojuk/dist/main.js:119:31
    at Generator.next (<anonymous>)
    at /Users/myyrakle/Study/eojuk/dist/main.js:9:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/myyrakle/Study/eojuk/dist/main.js:5:12)
    at main (/Users/myyrakle/Study/eojuk/dist/main.js:43:12)
    at Object.<anonymous> (/Users/myyrakle/Study/eojuk/dist/main.js:131:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)

However, if you specify NULL or Not NULL for deleted_at, it works normally.

I think it should work even without the null clause.

Thanks to you, I'm using it well, and thank you for your hard work.

oguimbal commented 1 year ago

Hi, this code does not seem to be related to this library (there is no "parseTable" function in pgsql-ast-parser).

You seem to be on the wrong repo :)