Hi
maybe you can check this PostgresqlSqlDialect#PostgresqlSqlDialect

Regards!

Aron Tao


Julian Hyde <[email protected]> 于2021年5月20日周四 上午7:20写道:

> The SQL string you posted does not contain the word “PRIMARY”, so the
> error message is surprising.
>
> That said, Calcite’s dialect is different from PostgreSQL, and we do not
> promise to be able to parse every PostgreSQL query. You might have a better
> chance with Babel parser, which is more lenient.
>
>
> > On May 19, 2021, at 2:47 PM, Meadows, Eric A. <
> [email protected]> wrote:
> >
> >
> > Hello,
> >
> > I am using Calcite's SqlParser, but I am running into a few issues with
> Postgres queries, namely that `PRIMARY`, `TIME`, and `ZONE` are not being
> properly parsed (raising an exception, instead).  The following code is
> what I am working with:
> >
> > ```java
> > import org.apache.calcite.sql.parser.SqlParser;
> > import org.apache.calcite.sql.ddl.SqlCreateTable;
> >
> > …
> >
> > SqlParser.Config sqlParserConfig = SqlParser
> >    .configBuilder()
> >    .setParserFactory(SqlDdlParserImpl.FACTORY)
> >    .build();
> > String sql = "CREATE TABLE \"elements_elementcomponent\" (\"id\"
> bigserial NOT NULL, \"created_at\" timestamp with time zone NOT NULL,
> \"updated_at\" timestamp with time zone NOT NULL, \"version\" double
> precision NOT NULL, \"git_sha\" varchar(60) NOT NULL, \"element_id\" bigint
> NULL, \"element_item_id\" bigint NULL, \"element_basket_id\" bigint NULL);";
> > SqlParser parser = SqlParser.create(sql, sqlParserConfig);
> > SqlCreateTable stmt = (SqlCreateTable) parser.parseQuery();
> > ```
> >
> > The following error, with the above keywords, occurs:
> > ```java
> > org.apache.calcite.sql.parser.SqlParseException: Encountered "PRIMARY"
> at line 1, column 69.
> > Was expecting one of:
> >    "AS" ...
> >    "DEFAULT" ...
> >    "GENERATED" ...
> >    ")" ...
> >    "," ...
> >
> >                at
> org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl.convertException(SqlDdlParserImpl.java:394)
> >                at
> org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl.normalizeException(SqlDdlParserImpl.java:157)
> >                at
> org.apache.calcite.sql.parser.SqlParser.handleException(SqlParser.java:140)
> >                at
> org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:155)
> >                at .(#110:1)
> > ```
> >
> > I'm not sure why this would happen, because those keywords appear
> supported in [Apache Calcite - SQL language - Keywords](
> https://calcite.apache.org/docs/reference.html#keywords).
> >
> > Cheers,
> > Eric
>
>

Reply via email to