pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: Laurent Mazuel <lmazuel@antidot.net>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: Case-sensitive problem in AS clause?
Date: Mon, 16 Jul 2012 10:05:29 -0600
Message-ID: <50043BC9.2090401@ttc-cmc.net> (raw)
In-Reply-To: <5004221A.4030508@antidot.net>
References: <5004221A.4030508@antidot.net>

Laurent Mazuel wrote:
> Dear all,
>
> I maybe found a problem with the "isCaseSensitive" method in the
> "ResultSetMetadata" class when using it on a "AS" clause.
>
>> test=> Select ('Student' || "ID" ) AS StudentId, "ID", "Name" from
> The StudentId regular identifier becomes studentid, but this kind of
> transformation is not a problem, since a regular identifier is not case
> sensitive.

Select ('Student' || "ID" ) AS "StudentId", "ID", "Name" from "Student"

Quoting the "StudentID" will make it case sensitive for you resultset.

>
> The problem is where I execute my query in JDBC:
>> ~
>> ~
>>~
>> s.executeQuery("Select ('Student' || \"ID\" ) AS StudentId from
>> \"Student\";");
>> ResultSet rs = s.getResultSet();
>> ResultSetMetaData metaData = rs.getMetaData();
>> int n = metaData.getColumnCount();
>> for (int i = 1; i <= n; i++) {
>> System.out.println("Column: "+metaData.getColumnLabel(i)+"
>> "+metaData.isCaseSensitive(i));
>> }
>> }
> I obtain the output:
>> Column: studentid true

Again as the as identifier is not quoting it default to the default
behavior for assignment. As far as the isCaseSensitive() it is found
that the method in the Pgjdbc, 
org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java is:

/*
      * Does a column's case matter? ASSUMPTION: Any field that is
      * not obviously case insensitive is assumed to be case sensitive
      *
      * @param column the first column is 1, the second is 2...
      * @return true if so
      * @exception SQLException if a database access error occurs
      */
     public boolean isCaseSensitive(int column) throws SQLException
     {
         Field field = getField(column);
         return connection.getTypeInfo().isCaseSensitive(field.getOID());
     }

As indicated by the comment, case is going to be assumed case sensitive,
true. Since the column is a result of AS clause it seems to be assigned
as a generic PGObject type. That type would then to be case insensitive.

>
> Then, the column name is changed from StudentId to studentid, but the
> "isCaseSensitive" flag is "true". I think it is not correct, since it is
> impossible from now, when a user ask for the StudentId column to
> retrieve it from a resultset. The "isCaseSensitive" don't authorize to
> accept the string StudentId as a valid column name for the studentid
> column in the ResultSet.

Recommed you quote AS "StudentID" to get the behavior you desire.

danap.




view thread (9+ messages)  latest in thread

Message-ID: <50043BC9.2090401@ttc-cmc.net>
Permalink:  ../50043BC9.2090401@ttc-cmc.net/
Also on:    postgresql.org/message-id/50043BC9.2090401@ttc-cmc.net

 · 

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: danap@ttc-cmc.net, lmazuel@antidot.net
  Subject: Re: Case-sensitive problem in AS clause?
  In-Reply-To: <50043BC9.2090401@ttc-cmc.net>
  References: <5004221A.4030508@antidot.net> <50043BC9.2090401@ttc-cmc.net>

* 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