I've got a quite strange situation. Below is a simple test
@Test
public void test() throws SQLException {
String query1 = "SELECT * FROM information_schema.schemata WHERE schema_name = ?";
String query2 = "SELECT * FROM pg_catalog.pg_namespace where nspname = ?";
check(query1, "1", "public");
check(query2, "2", "public");
}
private void check(final String query, final String info, final String param) throws SQLException {
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setString(1, param);
ResultSet schemas = stmt.executeQuery();
boolean exists = schemas.next();
System.out.println(info + " : " + exists);
}
The output is:
1 : false
2 : true
When I query the database using psql, both queries return sensible data (even when I prepare statements in postgres).
I'd like to use information_schema rather than using pg_catalog.
ENV:
Ubuntu 11.10
PostgreSQL 9.0.4 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
9.0-801.jdbc4
regards
Szymon