From: Thor Michael Støre <thormichael@gmail.com>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Finding exact column type via java.sql.ResultSetMetaData
Date: Thu, 14 Feb 2013 17:43:53 +0100
Message-ID: <3A2E457A-47D7-44B8-9D2F-5865D24C32DC@gmail.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
Hello,
I'm scratching my head over ResultSetMetaData yet again, this time related to figuring out the correct type of a column.
Am I right in understanding that given a SQL command whose resultset contains a field of a user defined type not originating from a table, you cannot look up the exact type for that field via the result set meta data if multiple types of the same name are defined in different schemas? AFAICT ResultSetMetaData only gives the name the type is defined with in the database, via getColumnTypeName, but not the schema of that type. Should the result for getColumnTypeName have been prefixed with schema-plus-dot, or is that not possible or not according to the spec? Unless I'm missing something the code I'm writing will basically have to throw an exception and apologize that different types with the same name in different schemas is not supported when it runs into that.
I'm testing with:
CREATE SCHEMA test_schema;
CREATE SCHEMA another_test_schema;
CREATE TYPE test_schema.test_type AS ( intfield int, textfield varchar );
CREATE TYPE another_test_schema.test_type AS ( other_textfield varchar, other_intfield int );
And given the query:
SELECT (1,'adsf')::test_schema.test_type, ('zxcv',2)::another_test_schema.test_type;
Then java.sql.ResultSetMetaData gives the exact same information for each column, with getColumnTypeName giving "test_type" for both. Simple test-case with this and a bit of runnable Java included.
Thanks,
Thor Michael Støre
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbcAttachments:
Testcase.java (application/octet-stream, 2.6K) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: thormichael@gmail.com
Subject: Re: Finding exact column type via java.sql.ResultSetMetaData
In-Reply-To: <3A2E457A-47D7-44B8-9D2F-5865D24C32DC@gmail.com>
References: <3A2E457A-47D7-44B8-9D2F-5865D24C32DC@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox