Hi all,
i’m trying to validate a sql query against a Postgres database, probably I
understand something incorrectly but I cannot find a good description how to
reference Postgres system catalogs, I try different variations of this code but
it fails:
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
final DataSource ds = JdbcSchema.dataSource(
"jdbc:postgresql://localhost:5432/postgres",
"org.postgresql.Driver",
"postgres",
"postgres");
rootSchema.add("pg_catalog", JdbcSchema.create(rootSchema, "pg_catalog", ds,
null, null));
FrameworkConfig config = Frameworks.newConfigBuilder()
.defaultSchema(rootSchema)
.build();
Planner planner = Frameworks.getPlanner(config);
SqlNode sqlNode = planner.parse("select * from pg_catalog.\"pg_tables\"");
System.out.println(sqlNode.toString());
sqlNode = planner.validate(sqlNode);
The exception is mostly this (I tried uppercase, lowercase and double quotes):
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Object
‘pg_catalog' not found; did you mean ‘PG_CATALOG'?
at
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Thanks