X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 21B1D3A4E1C for ; Sun, 23 Jan 2005 20:34:19 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35689-09 for ; Sun, 23 Jan 2005 20:34:10 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 30D913A4C67 for ; Sun, 23 Jan 2005 20:34:08 +0000 (GMT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CsoQr-00036q-00; Mon, 24 Jan 2005 09:34:01 +1300 Message-ID: <41F40A36.2030202@opencloud.com> Date: Mon, 24 Jan 2005 09:33:58 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0 (X11/20041228) X-Accept-Language: en-us, en MIME-Version: 1.0 To: leo Cc: pgsql-jdbc@postgresql.org Subject: Re: PGResultSetMetaData References: <01c701c50182$47c05350$7500000a@KALIO> In-Reply-To: X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/221 X-Sequence-Number: 12101 leo wrote: > Chris Smith: > >> ResultSet rs = stmt.executeQuery(...); >> ResultSetMetaData rmd = rs.getMetaData(); >> >> String table = rmd.getTableName(1); >> String schema = rmd.getSchemaName(1); > > Does this really work? > > Using Postgres 8 i am getting empty strings from both methods. getTableName() always returns an empty string, as the server does not tell us about table aliases. The same applies to getSchemaName(). getColumnName() will return the column alias. If you want the name of the underlying table and column, cast to PGResultSetMetadata and use getBaseTableName() / getBaseSchemaName() / getBaseColumnName(). These will return the table/schema/column name of the underlying relation, where available. For example, given this query: SELECT p.proname AS pname FROM pg_catalog.pg_proc p getTableName(1) returns "" getSchemaName(1) returns "" getColumnName(1) returns "pname" getBaseTableName(1) returns "pg_proc" getBaseSchemaName(1) returns "pg_catalog" getBaseColumnName(1) returns "proname" See http://archives.postgresql.org/pgsql-jdbc/2004-08/msg00008.php for the discussion that lead to this behaviour. (Kris, any reason why PGResultSetMetadata does not extend ResultSetMetadata?) -O