pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Tornroth, Phill <ptornroth@intellidot.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: FW: Question about the postgres resultset implementation
Date: Thu, 14 Oct 2004 10:06:48 +1300
Message-ID: <416D98E8.5090600@opencloud.com> (raw)
In-Reply-To: <BD92920D.12F1%ptornroth@intellidot.net>
References: <BD92920D.12F1%ptornroth@intellidot.net>

Tornroth, Phill wrote:

> I did some tinkering of my own and found that one of the problems with
> making the driver less cumbersome is the fact that findColumn() is currently
> case insensitive. I don't know if this is required by the jdbc spec, but it
> seems all the field names come back lower case (in the fields[] array), and
> so I could replace the implementation without understanding how to prevent
> the case of the field names from changing (changing from the case they were
> sent in as).

They come back lower-case because that's how they are in the actual 
schema. Unless you quote identifiers, they get smashed to lowercase by 
the backend:

>> test=> create table t1(lowercase integer, UPPERCASE integer, "QUOTEDUPPERCASE" integer);
>> CREATE TABLE
>> test=> select * from t1;
>>  lowercase | uppercase | QUOTEDUPPERCASE 
>> -----------+-----------+-----------------
>> (0 rows)

> At any rate, if case insensitivity could be thrown out then a very fast
> implementation could be worked out. As is, the following code was a marked
> improvement:

That change is slightly buggy as you *can* get uppercase characters in a 
field name.

We can't entirely discard case-insensitivy as JDBC requires that column 
names are found case-insensitively. This actually makes the use of 
column names somewhat unreliable if you ever have two columns with names 
that only differ by case. From the JDBC javadoc:

>> Column names used as input to getter methods are case insensitive. When
>> a getter method is called with a column name and several columns have
>> the same name, the value of the first matching column will be returned.
>> 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. If
>> column names are used, there is no way for the programmer to guarantee
>> that they actually refer to the intended columns.

(I am assuming that "findColumn" is considered a getter method.. the 
javadoc is vague as ever)

Nevertheless, we could certainly use a hashmap to speed up field 
lookups. This should be pretty trivial to implement, expect a patch shortly.

(hah, in fact I see that Kris got there first..)

-O



view thread (7+ messages)  latest in thread

Message-ID: <416D98E8.5090600@opencloud.com>
Permalink:  ../416D98E8.5090600@opencloud.com/
Also on:    postgresql.org/message-id/416D98E8.5090600@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, ptornroth@intellidot.net
  Subject: Re: FW: Question about the postgres resultset implementation
  In-Reply-To: <416D98E8.5090600@opencloud.com>
  References: <BD92920D.12F1%ptornroth@intellidot.net> <416D98E8.5090600@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