Dear dev,

I'm trying to parse a create table statement with foreign key into SqlNode
using the following code snippet:

String createTable = "CREATE TABLE emp (\n" +
        "    empno INTEGER,\n" +
        "    name VARCHAR NOT NULL,\n" +
        "    deptno INTEGER,\n" +
        "    FOREIGN KEY (deptno) REFERENCES dept(deptno)\n" +
        ")";
SqlParser.Config schemaParserConfig = SqlParser.Config.DEFAULT
        .withParserFactory(SqlDdlParserImpl.FACTORY)
        .withLex(Lex.MYSQL);
SqlParser schemaParser = SqlParser.create(createTable, schemaParserConfig);
SqlNode schemaNode = schemaParser.parseStmt();

but it seems that the parser (from calcite-server) could not recognize the
"FOREIGN" keyword and it will throw an exception. If the foreign key row is
commented out, while the trailing comma above is removed, this statement
could be parsed correctly.

If the parser supports foreign key constraints, how should I use it (or is
there anything wrong/missing in the code above)? Otherwise is there a
reason why the foreign key constraint is not supported? I would appreciate
any help on this.

Sincerely,
Arthur Pan

Reply via email to