Re: Wrong column names in ResultSetMetaData - Mailing list pgsql-jdbc

From Mike Martin
Subject Re: Wrong column names in ResultSetMetaData
Date
Msg-id cemmc3$2ke7$1@news.hub.org
Whole thread Raw
In response to Re: Wrong column names in ResultSetMetaData  ("Mike Martin" <mmartin@vieo.com>)
List pgsql-jdbc
Oliver wrote:
>    RSMD.getColumnName() returns the column alias
>    RSMD.getColumnLabel() returns the column alias, or maybe something
> like the column's comment (can you COMMENT ON columns?) later.
>    PGResultSetMetadata.getSourceColumnName() returns the underlying
> table column name. The driver's updateable resultset code can use this
> when constructing update SQL.

I like that, not just because I think it jives with the spec
but because a new method can explicitly document that the
source column name is not available if the result column has
multiple sources.

> On a related note, if I execute this query:
>
>    SELECT * FROM footable f
>
> should RSMD.getTableName() return "footable" or "f"? By analogy to
> RSMD.getColumnName() it should return "f", but it seems more useful to
> return "footable".

According to SQL "f" is the right answer.  One way convince yourself
is to observe the difference between:

     SELECT f.col FROM footable f
     SELECT footable.col FROM footable f

The former works as you might expect.  The latter fails on some
DBMS's and I'm pretty sure it's invalid SQL.  Interestingly, on
PG the latter is evaluated as though it were:

     SELECT f2.col FROM footable f1 CROSS JOIN footable f2

which for a footable of N rows returns N*N rows!

Mike



pgsql-jdbc by date:

Previous
From: "Mike Martin"
Date:
Subject: Re: Wrong column names in ResultSetMetaData
Next
From: Kris Jurka
Date:
Subject: Re: Wrong column names in ResultSetMetaData