From: dmp <danap@ttc-cmc.net>
To: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bug in DatabaseMetaData.getColumns() with columns based on domains
Date: Thu, 21 Oct 2010 19:25:36 -0600
Message-ID: <4CC0E810.7010406@ttc-cmc.net> (raw)
In-Reply-To: <i9q79p$sp1$1@dough.gmane.org>
References: <i9pdb3$6t5$1@dough.gmane.org>
<i9q79p$sp1$1@dough.gmane.org>
Thomas Kellerer wrote:
> Thomas Kellerer wrote on 21.10.2010 14:57:
>> Hi,
>>
>> consider the following table and domain:
>>
>> CREATE DOMAIN salary_domain AS numeric(12,2) NOT NULL CHECK (value > 0);
>> CREATE TABLE employee (id integer not null, salary salary_domain);
>>
>> DatabaseMetaData.getColumns(null, "public", "employee", "%");
>>
>> returns "YES" for the column IS_NULLABLE in the ResultSet whereas it
>> should flag that column as not nullable.
>>
>
> OK, I realized that not even psql or pgAdmin will display such a column
> as "not null"
> So it is not a JDBC driver issue (but rather a PostgreSQL "core" issue)
>
> Sorry for the noise
> Thomas
>
>
When the table field salary is defined directly the correct attribute for
IS_NULLABLE is returned by the DatabaseMetaData.getColumns(). When the
field is defined indirectly through the DOMAIN then the database appears
to be not setting the attnotnull entry correspondingly. As you indicated
I would also say it is the database. The attached files indicate the sql
statement generated by the JDBC and the result set for the getColumns()
for the table.
The early attached file query for the column's information was from the
information_schema.columns table and does show the correct result for the
salary field IS_NULLABLE.
danap.
Attachments:pgjdbc_column_select.sql (text/plain, 993B) download
SELECT * FROM (SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,row_number() OVER (PARTITION BY a.attrelid ORDER BY a.attnum) AS attnum, pg_catalog.pg_get_expr(def.adbin, def.adrelid) AS adsrc,dsc.description,t.typbasetype,t.typtype FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid) LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid AND a.attnum = dsc.objsubid) LEFT JOIN pg_catalog.pg_class dc ON (dc.oid=dsc.classoid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND dn.nspname='pg_catalog') WHERE a.attnum > 0 AND NOT a.attisdropped AND n.nspname LIKE 'public' AND c.relname LIKE 'employee' ) c WHERE true AND attname LIKE '%' ORDER BY nspname,c.relname,attnum
employee_columns2_20101021.pdf (application/pdf, 2.1K) download
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, spam_eater@gmx.net
Subject: Re: Bug in DatabaseMetaData.getColumns() with columns based on domains
In-Reply-To: <4CC0E810.7010406@ttc-cmc.net>
References: <i9pdb3$6t5$1@dough.gmane.org> <i9q79p$sp1$1@dough.gmane.org> <4CC0E810.7010406@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