From: Oliver Jowett <oliver@opencloud.com>
To: leo <usenet@workfile.de>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: PGResultSetMetaData
Date: Mon, 24 Jan 2005 09:33:58 +1300
Message-ID: <41F40A36.2030202@opencloud.com> (raw)
In-Reply-To: <tl7l0tocpvg6.1rfovtffloi2o.dlg@40tude.net>
References: <kr5so79kvul8$.1haqd7ypkt8g9$.dlg@40tude.net>
<01c701c50182$47c05350$7500000a@KALIO>
<tl7l0tocpvg6.1rfovtffloi2o.dlg@40tude.net>
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
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: oliver@opencloud.com, usenet@workfile.de
Subject: Re: PGResultSetMetaData
In-Reply-To: <41F40A36.2030202@opencloud.com>
References: <kr5so79kvul8$.1haqd7ypkt8g9$.dlg@40tude.net> <01c701c50182$47c05350$7500000a@KALIO> <tl7l0tocpvg6.1rfovtffloi2o.dlg@40tude.net> <41F40A36.2030202@opencloud.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