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 17:36:07 -0500
Message-ID: <cebu4m$sjp$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>
	<cebd4c$2ku1$1@news.hub.org>
	<Pine.BSO.4.56.0407291637280.9570@leary.csoft.net>

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.

From http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame5.html:

    Due to differences in database implementations, the JDBC API
    does not specify an exact set of SQL queries which must yield
    an updatable result set for JDBC drivers that support
    updatability.  Developers can, however, generally expect
    queries which meet the following criteria to produce an
    updatable result set:

    1.  The query references only a single table in the database.
    2.  The query does not contain any join operations.
    3.  The query selects the primary key of the table it references.

    In addition, an SQL query should also satisfy the conditions
    listed below if inserts are to be performed.

    4.  The query selects all of the non-nullable columns in the
        underlying table.
    5.  The query selects all columns that don't have a default
        value.

Mike





view thread (27+ messages)  latest in thread

Message-ID: <cebu4m$sjp$1@news.hub.org>
Permalink:  ../cebu4m$sjp$1@news.hub.org/
Also on:    postgresql.org/message-id/cebu4m$sjp$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: <cebu4m$sjp$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> <Pine.BSO.4.56.0407291637280.9570@leary.csoft.net> <cebu4m$sjp$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