pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Columns with domains from other schemas and DatabaseMetaData
Date: Fri, 22 Oct 2010 09:41:34 +0200
Message-ID: <i9rf7e$bac$1@dough.gmane.org> (raw)

Hi,

I have noticed another problem with DatabaseMetaData.getColumns() and domains.

If a domain is created in a different schema than the table, psql will show the fully qualified name of the domain when doing a "\d table"

When retrieving the column definition of such a table using getColumns() the column TYPE_NAME from the obtained resultset will contain the domain name without the schema.

As an example:

CREATE SCHEMA other;
CREATE DOMAIN other.salary_domain AS numeric(12,2) NOT NULL CHECK (value > 0);
CREATE TABLE employee (id integer not null, salary other.salary_domain);
COMMIT;

 From psql, the following is displayed for this table:

psql (9.0.1)
Type "help" for help.

postgres=> \d employee
          Table "public.employee"
  Column |        Type         | Modifiers
--------+---------------------+-----------
  id     | integer             | not null
  salary | other.salary_domain |


postgres=>

Unfortunately the JDBC driver does not return the fully qualified name of the domain as psql does.
Although according to the JDBC Javacods, TYPE_NAME is described as "for a UDT the type name is fully qualified".

This is the sample Java code:

Connection con = DriverManager.getConnection(...)
ResultSet rs = con.getMetaData().getColumns(null, "public", "employee", "%");
while (rs.next())
{
   String col = rs.getString("COLUMN_NAME");
   String type = rs.getString("TYPE_NAME");
   System.out.println(col + ": " + type);
}

Will print:

id: integer
salary: salary_domain


I tried this with PostgreSQL 9.0.1 and the 9.0-801 JDBC driver.

It would nice if this could be fixed in a future version of the driver.

Thanks
Thomas




Message-ID: <i9rf7e$bac$1@dough.gmane.org>
Permalink:  ../i9rf7e$bac$1@dough.gmane.org/
Also on:    postgresql.org/message-id/i9rf7e$bac$1@dough.gmane.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: spam_eater@gmx.net
  Subject: Re: Columns with domains from other schemas and DatabaseMetaData
  In-Reply-To: <i9rf7e$bac$1@dough.gmane.org>
  References: <i9rf7e$bac$1@dough.gmane.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