Re: PGResultSetMetaData

Lists: pgsql-jdbc
From: leo <usenet(at)workfile(dot)de>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: PGResultSetMetaData
Date: 2005-01-23 19:14:30
Message-ID: kr5so79kvul8$.1haqd7ypkt8g9$.dlg@40tude.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hello,

as I need getTableName() and getSchemaName() I found
the interface PGResultSetMetaData.
Is ist still experimental?
Has anybody used it already? If so, could you give me
a hint how to implement it?

Thank you,
Rainer Leo


From: "Chris Smith" <cdsmith(at)twu(dot)net>
To: "leo" <usenet(at)workfile(dot)de>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: PGResultSetMetaData
Date: 2005-01-23 19:32:30
Message-ID: 01c701c50182$47c05350$7500000a@KALIO
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

leo wrote:
> as I need getTableName() and getSchemaName() I found
> the interface PGResultSetMetaData.
> Is ist still experimental?
> Has anybody used it already? If so, could you give me
> a hint how to implement it?

It's not experimental. However, instead of using the PostgreSQL
implementation class, you should stick to the JDBC API.

ResultSet rs = stmt.executeQuery(...);
ResultSetMetaData rmd = rs.getMetaData();

String table = rmd.getTableName(1);
String schema = rmd.getSchemaName(1);

(just for example)

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


From: leo <usenet(at)workfile(dot)de>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PGResultSetMetaData
Date: 2005-01-23 19:49:59
Message-ID: tl7l0tocpvg6.1rfovtffloi2o.dlg@40tude.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

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.


From: Dave Cramer <davec(at)fastcrypt(dot)com>
To: leo <usenet(at)workfile(dot)de>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PGResultSetMetaData
Date: 2005-01-23 20:02:59
Message-ID: 41F402F3.8010802@fastcrypt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Look at the test suite, you can see how the code is used there

Dave
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.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
>
>
>


From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: leo <usenet(at)workfile(dot)de>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PGResultSetMetaData
Date: 2005-01-23 20:10:34
Message-ID: 41F404BA.2020801@fastcrypt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Leo,

Here is the documentation of the interface

/**
* Returns the underlying table name of query result, or ""
* if it is unable to be determined.
*
* @since 8.0
*/
public String getBaseTableName(int column) throws SQLException;

/**
* Returns the underlying table name of query result, or ""
* if it is unable to be determined.
*
* @since 8.0
*/
public String getBaseSchemaName(int column) throws SQLException;

So I'm guessing your query makes it difficult to find the table names
and the schema names.

What is your query?

Dave

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.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
>
>
>

--
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561


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: 41F40A36.2030202@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
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 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


From: leo <usenet(at)workfile(dot)de>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PGResultSetMetaData
Date: 2005-01-23 21:30:47
Message-ID: 15valw51r9pyw$.16kocrwa6l7pr$.dlg@40tude.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

> cast to PGResultSetMetadata...
That works perfectly.

Thank you very much for your help.


From: Kris Jurka <books(at)ejurka(dot)com>
To: Oliver Jowett <oliver(at)opencloud(dot)com>
Cc: leo <usenet(at)workfile(dot)de>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PGResultSetMetaData
Date: 2005-01-24 08:07:23
Message-ID: Pine.BSO.4.56.0501240257530.23058@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Mon, 24 Jan 2005, Oliver Jowett wrote:

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

Never really thought about it. Note that PGStatement and PGConnection
don't extend the java.sql versions, instead there are BaseXXX versions
that extend the pg and java.sql versions that the Abstract classes
implement. I'm confused as to how this actually works because the
Abstract classes don't implement the full java.sql interface. Then the
real JdbcX classes also claim to implement the java.sql inteface and
actually do.

In any case what we have now is a little confusing internally, but
externally it is consistent.

Kris Jurka