Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U61ui-0003if-8h for pgsql-jdbc@arkaria.postgresql.org; Thu, 14 Feb 2013 16:44:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U61uh-0006tf-Pk for pgsql-jdbc@arkaria.postgresql.org; Thu, 14 Feb 2013 16:43:59 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U61uh-0006ta-4K for pgsql-jdbc@postgresql.org; Thu, 14 Feb 2013 16:43:59 +0000 Received: from mail-lb0-f174.google.com ([209.85.217.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U61ue-0004pj-Sl for pgsql-jdbc@postgresql.org; Thu, 14 Feb 2013 16:43:58 +0000 Received: by mail-lb0-f174.google.com with SMTP id l12so1959884lbo.19 for ; Thu, 14 Feb 2013 08:43:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:content-type:subject:message-id:date:to :mime-version:x-mailer; bh=Oz6z63LPpgxN9soXpW118ijt+WjNLjf5LSFpja3Jyb4=; b=QH7v5Yjw73DcDEPfMYE5lA6fRXteWHtRUWTFL6zG4rEVinxstjSRJj4fFWOBic17tZ /Dcxdk5xC1QftR7oqnpBhvoqhcQaJll1NgasjM3q4mJUxUNHQPQJledJG/XJXqwh9pLt T5WxrPt7e5HgHrf5rqabzZcADsJUSg7Ir7atMBiJIN9QskcJp+RsneZV4yV2/w9RjK2N 2dQun2nmuWORe1I9D49HKnLIqpJbCGe7Tu+Q6Mv6zwcUFdRvcEx8C4gUcze9M29VUb5/ W9Zf6Ci04I1A0raCjrQSU9mDDiodtUsKDJUg8PvPrO/X4TQ1SfUERmpjFVaumHgAeJ0C u2FQ== X-Received: by 10.112.42.37 with SMTP id k5mr888043lbl.49.1360860236266; Thu, 14 Feb 2013 08:43:56 -0800 (PST) Received: from [10.0.0.3] ([80.202.62.252]) by mx.google.com with ESMTPS id oy10sm27970244lab.8.2013.02.14.08.43.54 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Feb 2013 08:43:55 -0800 (PST) From: =?iso-8859-1?Q?Thor_Michael_St=F8re?= Content-Type: multipart/mixed; boundary="Apple-Mail=_776B8663-3A0F-440F-9832-FAD9DD1AF0EC" Subject: Finding exact column type via java.sql.ResultSetMetaData Message-Id: <3A2E457A-47D7-44B8-9D2F-5865D24C32DC@gmail.com> Date: Thu, 14 Feb 2013 17:43:53 +0100 To: "pgsql-jdbc@postgresql.org" Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) X-Mailer: Apple Mail (2.1499) X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --Apple-Mail=_776B8663-3A0F-440F-9832-FAD9DD1AF0EC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 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 contai= ns 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 multi= ple types of the same name are defined in different schemas? AFAICT ResultS= etMetaData only gives the name the type is defined with in the database, vi= a 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 cod= e 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 wh= en 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, oth= er_intfield int ); And given the query: SELECT (1,'adsf')::test_schema.test_type, ('zxcv',2)::another_test_schema.t= est_type; Then java.sql.ResultSetMetaData gives the exact same information for each c= olumn, with getColumnTypeName giving "test_type" for both. Simple test-case= with this and a bit of runnable Java included. Thanks, Thor Michael St=F8re --Apple-Mail=_776B8663-3A0F-440F-9832-FAD9DD1AF0EC Content-Disposition: attachment; filename=Testcase.java Content-Type: application/octet-stream; name="Testcase.java" Content-Transfer-Encoding: 7bit /* 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 ); Query: SELECT (1,'adsf')::test_schema.test_type, ('zxcv',2)::another_test_schema.test_type // This variant gives enough information to look up the schema, but isn't what I'm testing for: CREATE TABLE test_schema.test_table ( first_testfield test_schema.test_type, second_testfield another_test_schema.test_type ); Query: SELECT first_testfield, second_testfield FROM test_schema.test_table */ package tmdbctest; import java.sql.*; import org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData; public class Testcase { public static Connection getConnection() throws SQLException { return DriverManager.getConnection( "jdbc:postgresql://localhost/postgres?user=postgres"); // trust access to user with access to both schemas } public static void main(String[] args) throws Exception { PreparedStatement stmnt = getConnection().prepareStatement( "SELECT (1,'adsf')::test_schema.test_type, ('zxcv',2)::another_test_schema.test_type" ); AbstractJdbc2ResultSetMetaData metaData = (AbstractJdbc2ResultSetMetaData) stmnt.getMetaData(); for(int i = 1; i <= metaData.getColumnCount() ; i++ ){ System.out.println( "Column "+ i ); System.out.println( " CatalogName: "+ metaData.getCatalogName(i) ); System.out.println( " SchemaName: "+ metaData.getSchemaName(i) ); System.out.println( " TableName: "+ metaData.getTableName(i) ); System.out.println( " ColumnName: "+ metaData.getColumnName(i) ); System.out.println( " ColumnLabel: "+ metaData.getColumnLabel(i) ); System.out.println( " ColumnType: "+ metaData.getColumnType(i) ); System.out.println( " ColumnTypeName: "+ metaData.getColumnTypeName(i) ); System.out.println( " ColumnClassName: "+ metaData.getColumnClassName(i) ); System.out.println( " ColumnDisplaySize: "+ metaData.getColumnDisplaySize(i) ); System.out.println( " Precision: "+ metaData.getPrecision(i) ); System.out.println( " Scale: "+ metaData.getScale(i) ); // AbstractJdbc2ResultSetMetaData specific columns: System.out.println( " BaseSchemaName: "+ metaData.getBaseSchemaName(i) ); System.out.println( " BaseTableName: "+ metaData.getBaseTableName(i) ); System.out.println( " BaseColumnName: "+ metaData.getBaseColumnName(i) ); } stmnt.close(); } } --Apple-Mail=_776B8663-3A0F-440F-9832-FAD9DD1AF0EC Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_776B8663-3A0F-440F-9832-FAD9DD1AF0EC Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc --Apple-Mail=_776B8663-3A0F-440F-9832-FAD9DD1AF0EC--