pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Kris Jurka <books@ejurka.com>
Cc: Mike Martin <mmartin@vieo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Wrong column names in ResultSetMetaData
Date: Tue, 03 Aug 2004 11:57:26 +1200
Message-ID: <410ED4E6.8020806@opencloud.com> (raw)
In-Reply-To: <Pine.BSO.4.56.0408021705100.21355@leary.csoft.net>
References: <ce9dna$pne$1@news.hub.org>
	<ce9jk0$15mb$1@news.hub.org>
	<41086EF8.7010101@opencloud.com>
	<celqa5$i2c$1@news.hub.org>
	<Pine.BSO.4.56.0408021308010.29090@leary.csoft.net>
	<cembfp$1tpn$1@news.hub.org>
	<Pine.BSO.4.56.0408021705100.21355@leary.csoft.net>

Kris Jurka wrote:

> This shows the results are different, but it doesn't indicate why.  Is it 
> simply because the other dbs can't implement getColumnName as we have?  
> I certainly wouldn't expect this to be a common feature.
> 
> Further it doesn't show that users can't write portable code using the 
> ResultSetMetaData calls.  It shows all drivers returning the same value 
> for getColumnLabel that you would expect.  Earlier you had speculated that 
> other drivers would return something different for this, but you haven't 
> shown that.  Yes it may break existing code, but it doesn't show that they 
> weren't simply using the wrong call.

I'm leaning towards Mike's argument here. It seems reasonable that the 
column name returned is the same as what you'd use to look up a column 
by name via ResultSet, and the only sensible thing to do in ResultSet 
lookups is to use the column aliases.

The argument for exposing the real column name as a way to allow 
portable updating of the underlying table seems weak given that other 
drivers don't support the same behaviour. The more portable behaviour 
seems to be to always use getColumnName() and forbid the use of AS in 
queries that you want to be updatable.

getColumnLabel() isn't the right place for the underlying column name, 
though. JDBC doesn't actually seem to have a mapping for this concept at 
all. I'd suggest adding a PG-specific interface if we want to expose 
this. How about:

   RSMD.getColumnName() returns the column alias
   RSMD.getColumnLabel() returns the column alias, or maybe something 
like the column's comment (can you COMMENT ON columns?) later.
   PGResultSetMetadata.getSourceColumnName() returns the underlying 
table column name. The driver's updateable resultset code can use this 
when constructing update SQL.

On a related note, if I execute this query:

   SELECT * FROM footable f

should RSMD.getTableName() return "footable" or "f"? By analogy to 
RSMD.getColumnName() it should return "f", but it seems more useful to 
return "footable".

-O



view thread (27+ messages)  latest in thread

Message-ID: <410ED4E6.8020806@opencloud.com>
Permalink:  ../410ED4E6.8020806@opencloud.com/
Also on:    postgresql.org/message-id/410ED4E6.8020806@opencloud.com

 · 

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: oliver@opencloud.com, books@ejurka.com, mmartin@vieo.com
  Subject: Re: Wrong column names in ResultSetMetaData
  In-Reply-To: <410ED4E6.8020806@opencloud.com>
  References: <ce9dna$pne$1@news.hub.org> <ce9jk0$15mb$1@news.hub.org> <41086EF8.7010101@opencloud.com> <celqa5$i2c$1@news.hub.org> <Pine.BSO.4.56.0408021308010.29090@leary.csoft.net> <cembfp$1tpn$1@news.hub.org> <Pine.BSO.4.56.0408021705100.21355@leary.csoft.net> <410ED4E6.8020806@opencloud.com>

* 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