pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [PATCH] problem with DatabaseMetaData and mixed case
Date: Mon, 8 Aug 2005 16:55:30 -0500 (EST)
Message-ID: <Pine.BSO.4.56.0508081646440.22483@leary.csoft.net> (raw)
In-Reply-To: <1123518043.6487.4.camel@localhost>
References: <1123518043.6487.4.camel@localhost>



On Mon, 8 Aug 2005, Giuseppe Sacco wrote:

> Connection c = ...;
> Statement s = c.createStatement();
> 
> s.execute("create table MyTable ( PK numeric(10), primary key(pk))");
> 
> DatabaseMetaData md = c.getMetaData();
> ResultSet rs = md.getPrimaryKeys(null,null, "MyTable")
> 
> while (rs.next())
> 	System.out.println("table: \"" + rs.getString("TABLE_NAME") + 
> 	"\", column: \"" + rs.getString("COLUMN_NAME") + "\".");
> 
> rs.close();
> s.close();
> c.close();
> ---------------------------------------------------------
> 
> The resultset is empty, while it should contain a line for the
> "PK" field.
> 
> If I lowercase the table name in «getPrimaryKeys» call than everything
> works.
> My question is: how do I know that postgresql changed my table name?
> 
> The solution I propose is, since it seems that postgresql always store
> relation names in lowercase letters, to change the jdbc implementation
> of all methods like «getPrimaryKeys» in order to pass lowercase relation
> names to the backend.

Postgresql folds identifiers to lowercase as long as they are created
without quotes.  Using CREATE TABLE "MyTable" (...) will indeed retain the
case of MyTable.  We do not fold DatabaseMetaData parameters to lowercase
because that would prevent you from retrieving data from a table created
as "MyTable".  The DatabaseMetaData methods like
storesLowerCaseIdentifiers() helps allow portable code to call the other
methods with the correct name.  It doesn't help you if you don't know if 
the table name was originally created as MyTable or "MyTable", but if 
that's the case a call to getTables may be in order.

Kris Jurka




view thread (4+ messages)  latest in thread

Message-ID: <Pine.BSO.4.56.0508081646440.22483@leary.csoft.net>
Permalink:  ../Pine.BSO.4.56.0508081646440.22483@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.56.0508081646440.22483@leary.csoft.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: books@ejurka.com, giuseppe@eppesuigoccas.homedns.org
  Subject: Re: [PATCH] problem with DatabaseMetaData and mixed case
  In-Reply-To: <Pine.BSO.4.56.0508081646440.22483@leary.csoft.net>
  References: <1123518043.6487.4.camel@localhost> <Pine.BSO.4.56.0508081646440.22483@leary.csoft.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