Re: PGResultSetMetaData

From: "Barry Lind" <blind(at)xythos(dot)com>
To: "Oliver Jowett" <oliver(at)opencloud(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: PGResultSetMetaData
Date: 2005-01-24 17:29:00
Message-ID: 03E7D3E231BB7B4A915A6581D4296CC6EC5862@NSNOVPS00411.nacio.xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

>>(Kris, any reason why PGResultSetMetadata does not extend
>>ResultSetMetadata?)

By ResultSetMetadata I assume you mean java.sql.ResultSetMetadata. The
problem with having PGResultSetMetadata extend that interface is which
one would you end up extending? The JDBC1, JDBC2, JDBC3 or JDBC4
version?

--Barry

-----Original Message-----
From: pgsql-jdbc-owner(at)postgresql(dot)org
[mailto:pgsql-jdbc-owner(at)postgresql(dot)org] On Behalf Of Oliver Jowett
Sent: Sunday, January 23, 2005 12:34 PM
To: leo
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [JDBC] PGResultSetMetaData

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

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2005-01-24 17:35:12 Versioned vs unversioned jarfile names?
Previous Message Vadim Nasardinov 2005-01-24 16:59:31 Re: context classloader