Skip site navigation (1) Skip section navigation (2)

Re: PGResultSetMetaData

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: leo <usenet(at)workfile(dot)de>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PGResultSetMetaData
Date: 2005-01-23 20:33:58
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
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 for 
the discussion that lead to this behaviour.

(Kris, any reason why PGResultSetMetadata does not extend 


In response to


pgsql-jdbc by date

Next:From: leoDate: 2005-01-23 21:30:47
Subject: Re: PGResultSetMetaData
Previous:From: Dave CramerDate: 2005-01-23 20:10:34
Subject: Re: PGResultSetMetaData

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group