From: Mike Martin <mmartin@vieo.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Wrong column names in ResultSetMetaData
Date: Wed, 28 Jul 2004 20:24:00 -0500
Message-ID: <ce9jk0$15mb$1@news.hub.org> (raw)
References: <ce9dna$pne$1@news.hub.org>
I wrote:
> With the new V3 driver the column names in ResultSetMetaData
> don't reflect the aliases used in the SQL. I.e. if I do:
>
> SELECT name as name_alias FROM ...
>
> the metadata says I have a result column called "name" instead
> of "name_alias".
I think I see the problem. v2/QueryExecutorImpl.java:400 says:
fields[i] = new Field(columnLabel, columnLabel, typeOid, typeLength,
typeModifier, 0, 0);
whereas v3/QueryExecutorImpl.java:1097 says:
fields[i] = new Field(columnLabel,
null, /* name not yet determined */
typeOid, typeLength, typeModifier, tableOid,
positionInTable);
and a separate query is later done in getColumnName() to try
to return the unaliased *source* column name used in the query.
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);
for every column that has a (non-duplicate) name.
I have to think this is going to break more code than just
ours.
Mike
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: mmartin@vieo.com
Subject: Re: Wrong column names in ResultSetMetaData
In-Reply-To: <ce9jk0$15mb$1@news.hub.org>
References: <ce9dna$pne$1@news.hub.org> <ce9jk0$15mb$1@news.hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox