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: "Mike Martin" <mmartin(at)vieo(dot)com>
  • To: pgsql-jdbc(at)postgresql(dot)org
  • Subject: Re: Wrong column names in ResultSetMetaData
  • Date: Thu, 29 Jul 2004 17:36:07 -0500
  • Message-id: <cebu4m$sjp$1@news.hub.org> <text/plain>

Kris Jurka wrote:
> > 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).
>
> What do they return for getColumnLabel()?  Previously we returned the same
> value for both methods simply because we couldn't implement getColumnName
> as we do now.  If they all return the alias in getColumnLabel that would
> be telling.

Most return the same thing as getColumnName(); not surprising
since that's a good default display title.  I've heard that
some drivers return a string containing extra metadata fluff
about the column type.

Consider:

    SELECT c1 + c2 FROM t1

The name/label distinction allows the DBMS/driver, if it wants,
to give the column a label for display purposes of, say,
"Expr c1+c2" or "Result, type=decimal(9,2)".  But the column
has no SQL name.  Nor could it have a name like "Expr c1+c2"
since that's not a valid SQL identifier.

> > 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.
>
> To allow client software to do the updates or allow the user to navigate
> from a query result column to the base table or to/through foreign keys on
> it.  There could be a number of uses.

What about:

    SELECT col1 AS price FROM t1
    UNION
    SELECT col2 AS price FROM t2

What is the "true" column name?  SQL says that query produces a
table with one column named "PRICE".

Client code simply can't reverse-engineer query result columns to
find their origins.  If a user is trying to do so for updating,
that's what updatable result sets are for, and that's why only a
small subset of queries are updatable.



Home | Main Index | Thread Index

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