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

Re: Wrong column names in ResultSetMetaData

From: "Mike Martin" <mmartin(at)vieo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Wrong column names in ResultSetMetaData
Date: 2004-08-03 00:32:09
Message-ID: cemmc3$2ke7$ (view raw, whole thread or download thread mbox)
Lists: 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!


In response to

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2004-08-03 00:41:49
Subject: Re: Wrong column names in ResultSetMetaData
Previous:From: Kris JurkaDate: 2004-08-03 00:31:20
Subject: Re: Wrong column names in ResultSetMetaData

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