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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: Wrong column names in ResultSetMetaData


  • From: Kris Jurka <books(at)ejurka(dot)com>
  • To: Mike Martin <mmartin(at)vieo(dot)com>
  • Cc: pgsql-jdbc(at)postgresql(dot)org
  • Subject: Re: Wrong column names in ResultSetMetaData
  • Date: Wed, 28 Jul 2004 22:20:46 -0500 (EST)
  • Message-id: <Pine.BSO.4.56.0407282213330.155@leary.csoft.net> <text/plain>


On Wed, 28 Jul 2004, Mike Martin wrote:

> I wrote:
> > [new driver returns a column alias as the label, not name]
> 
> I'm almost certain this is wrong from a JDBC standpoint.
> 
> rsmd.getColumnName() is supposed to return the given name of
> the *result* column, which SQL has rules to define.
> rsmd.getColumnLabel() is "for use in printouts and displays"
> and will often equate to the column name unless the DBMS has
> some "prettier" column title for display purposes.
> 
> For programmatic purposes the column name concept is pretty
> well defined by the docs on ResultSet.  They're supposed to
> behave such that:
> 
>    String colname = rsmd.getColumnName(col);
>    return rs.getXXX(colname);
> 
> is equivalent to:
> 
>    return rs.getXXX(col);
> 

I am not sure I see where it states that.  Your logic makes some sense, 
but I don't see anywhere it says the above explicity.  The problem is how 
to return both pieces of information (the alias and the underlying column 
name) within the JDBC API.  Certainly the alias makes more sense as the 
label when you have to pick between the two of them.

Would you expect the results of getTableName() to return the underlying
table or the table's alias in the query?  To be consistent with your 
argument you'd have to claim the alias name which is useless here.

Further code doesn't make a whole lot of sense doing:

rs.getString(rsmd.getColumnName(1));

Why wouldn't it just do:

rs.getString(1);

Kris Jurka




Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group