getPrimaryKeys() bug in JDBC driver (fix) - Mailing list pgsql-interfaces

From Jens Glaser
Subject getPrimaryKeys() bug in JDBC driver (fix)
Date
Msg-id Pine.LNX.4.05.9908020315360.20222-100000@helena.jens.de
Whole thread Raw
Responses Re: getPrimaryKeys() bug in JDBC driver (fix)  (Peter Mount <peter@retep.org.uk>)
List pgsql-interfaces
Hi,

as it looks the getPrimaryKeys function in the postgresql
jdbc driver is broken. With psql 6.5.1, it returns "garbage" because of a
wrong SQL query in DatabaseMetaData.getPrimaryKeys().

With my limited knowledge of the postgresql internas I think this is the
right query to get all the primary key columns of a table (here: 'test'):

select '' as TABLE_CAT, '' AS TABLE_SCHEM, bc.relname AS TABLE_NAME, a.attname AS COLUMN_NAME, a.attnum as KEY_SEQ,
ic.relnameas PK_NAME
 
from pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t
where bc.relkind = 'r' and upper(bc.relname) = upper('test') and i.indrelid = bc.oid and i.indexrelid = ic.oid  and
a.attrelid= ic.oid and i.indisprimary='t'
 
order by table_name, pk_name,key_seq;

Could you check that please?

Regards,

-- 
Jens Glaser     Am Holderstrauch 13, 36041 Fulda, 0661/9429507    jens@jens.de



pgsql-interfaces by date:

Previous
From: rodneyr@embratel.com.br
Date:
Subject: Opening database with PGACCESS
Next
From: "Oliver Elphick"
Date:
Subject: Re: [INTERFACES] Opening database with PGACCESS