Hi Egor, You could try with: select * from "pg_catalog"."pg_tables"
In CalciteParser, we have a config[1] for how to deal with unquoted identifier, and it's default value is TO_UPPER. That's why if you do not quote pg_catalog, it will try to match PG_CATALOG, and it could not match the name you registered with. You can configure it to UNCHANGED if you want. [1] https://calcite.apache.org/javadocAggregate/org/apache/calcite/sql/parser/SqlParser.Config.html#withQuotedCasing(org.apache.calcite.avatica.util.Casing) Egor Ryashin <[email protected]> 于2022年7月28日周四 18:50写道: > 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 > > -- Best, Benchao Li
