pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mike Martin <mmartin@vieo.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Wrong column names in ResultSetMetaData
Date: Thu, 29 Jul 2004 12:45:32 -0500
Message-ID: <cebd4c$2ku1$1@news.hub.org> (raw)
References: <ce9dna$pne$1@news.hub.org>
	<ce9jk0$15mb$1@news.hub.org>
	<Pine.BSO.4.56.0407282213330.155@leary.csoft.net>

"Kris Jurka" wrote:
> > For programmatic purposes the column name concept is pretty
> > well defined by the docs on ResultSet.
>
> 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.

It depends on how explicit you need it to be.  :)

Unfortunately the JDBC spec itself lacks much of anything that
explicit.  The Javadoc for ResultSet says:

    "The column name option is designed to be used when column
    names are used in the SQL query that generated the result set.
    For columns that are NOT explicitly named in the query, it
    is best to use column numbers."

I read "named" to mean named according to the usual SQL rules.
Combine that with the other references to the semantics of column
name (findColumn(), getXXX(colName)) and it seems like the
reasonable reading.

My other support is circumstantial:

1.  An SQL query produces a result set which is itself a table,
    that table has columns, those columns have names, and those
    names are defined according to SQL rules.  The column being
    named is that of the result table, not that of the underlying
    source(s) that contributed to it.  I can't imagine
    getColumnName() referring to any other concept.

2.  Every other JDBC driver I'm familiar with behaves that way
    (with the exception, I hear, of MimerSQL, which confuses
    getColumnLabel() with SQL alias the way our new code does).

I'm not clear why a JDBC client would want or need to know the
"underlying" column name, if there even is one.  I can see why
the driver might need to know that internally for purposes of
updateability but that's something different.

> 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.

The alias.  By SQL naming rules every column may also have a
table name component that can be used to disambiguate it from
other columns of the same name.  If a query represents a single
table expression, and that expression has been given an alias
name (aka "range variable"), then every column takes that alias
as its table name.

Likewise with getCatalogName(int) except I believe a column loses
any catalog affiliation as soon as it's aliased in any way.

> 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);

In real life you would.  I was just illustrating the expected
semantics.

Mike





view thread (27+ messages)  latest in thread

Message-ID: <cebd4c$2ku1$1@news.hub.org>
Permalink:  ../cebd4c$2ku1$1@news.hub.org/
Also on:    postgresql.org/message-id/cebd4c$2ku1$1@news.hub.org

 · 

reply

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: <cebd4c$2ku1$1@news.hub.org>
  References: <ce9dna$pne$1@news.hub.org> <ce9jk0$15mb$1@news.hub.org> <Pine.BSO.4.56.0407282213330.155@leary.csoft.net> <cebd4c$2ku1$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