JDBC problem in 10.3 / 10.4

From: John Bester <john(at)softco(dot)co(dot)za>
To: pgsql-bugs(at)postgresql(dot)org
Subject: JDBC problem in 10.3 / 10.4
Date: 2018-05-16 13:02:09
Message-ID: 3868dd51-1d38-f482-c43e-258beadfc091@softco.co.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-jdbc

I am using Connection.getMetaData().getTables(...) to auto generate

SQL statements (INSERT, UPDATE and DELETE). When upgrading

underlying databases to 10.3 and 10.4 on different servers, I started

getting problems. After some debugging I found that the meta

data returned by the same JDBC driver for the different server

versions are different.

If you debug the code below (I am using Eclipse) and

step through the code, the "originalQuery" property of the resultset

(which you can see in "rs" variable properties) differs. I have tested

the postgresql-42.2.2.jre7.jar and postgresql-9.4.1212.jar against

both servers and got the same problem.

Test Code: (Replace createConnection() to whatever you need)

try (Connectgion con = createConnection();

ResultSet rs = con.getMetaData().getTables(null, null, null, new String[] { "TABLE" })) {

while (rs.next()) {

String catalogue = rs.getString("TABLE_CAT");

String schema = rs.getString("TABLE_SCHEM");

String name = rs.getString("TABLE_NAME");

String type = rs.getString("TABLE_TYPE");

System.out.println(catalogue + " / " + schema + " / " + name + " / " + type);

}

}

"originalQuery" used when connecting to 9.5 server:

SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME, -- CASE STATEMENTS --

FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c

LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0)

LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class')

LEFT JOIN pg_catalog.pg_namespace dn ON (dn.oid=dc.relnamespace AND dn.nspname='pg_catalog')

WHERE c.relnamespace = n.oid AND (false OR ( c.relkind = 'r' AND n.nspname !~ '^pg_' AND n.nspname 'information_schema' ) )

ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME

"originalQuery" used when connecting to 10.4 server:

SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, c.relname AS TABLE_NAME, -- CASE STATEMENTS --

FROM pg_class c

WHERE true AND (false OR ( c.relkind = 'r' AND c.relname !~ '^pg_' ) )

ORDER BY TABLE_TYPE,TABLE_NAME

This shows clearly that LEFT JOINs are left out for 10.4 and NULL is simply returned for some columns. The full

statement actually works for 10.5, so there must be some other condition which determines the SQL used.

Kind regards










John Bester

Nexti SA PTY LTD

Tel. (023) 313 3011

john(at)softco(dot)co(dot)za






Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2018-05-16 13:36:43 BUG #15200: Support ANSI OFFSET .. FETCH syntax with bind variables
Previous Message PG Bug reporting form 2018-05-16 09:47:06 BUG #15199: relfrozenxid related corruption in pg_authid

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jorge Solorzano 2018-05-17 07:23:35 [pgjdbc/pgjdbc] f4d503: test: add coverage for extendedCacheEverything (#1...
Previous Message Vladimir Sitnikov 2018-05-15 14:45:23 Re: Reviewers needed for pgjdbc pull requests