Re: Bug in metadata.getColumns()/ORDINAL_POSITION

From: Kris Jurka <books(at)ejurka(dot)com>
To: "j(dot)random(dot)programmer" <javadesigner(at)yahoo(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Bug in metadata.getColumns()/ORDINAL_POSITION
Date: 2007-02-17 19:09:25
Message-ID: Pine.BSO.4.64.0702171404010.30813@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Fri, 16 Feb 2007, j.random.programmer wrote:

> This is using postgres 8.2.x and the latest 8.2-504
> JDBC driver.
>
> [DatabaseMetaData.getColumns returns wrong ordinal_position like so:]
>
> NOTE, THE COLNUM (via ("ORDINAL_POSITION")) returns:
> 1, 2, 3, 5, 6, 7
>
> This is WRONG. It should be:
> 1, 2, 3, 4, 5, 6
>

Turns out this is a problem with dropped columns:

CREATE TABLE test (a int, b int, c int);
ALTER TABLE test DROP b;
SELECT attname, attnum FROM pg_attribute
WHERE attnum > 0 AND attrelid = 'test'::regclass;

attname | attnum
------------------------------+--------
a | 1
........pg.dropped.2........ | 2
c | 3
(3 rows)

So we need to do our own counting in getColumns instead of relying on
attnum. I'll look at a fix, but for the moment a workaround would be to
recreate your table without any dropped columns.

Kris Jurka

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message j.random.programmer 2007-02-17 19:17:41 Re: Bug in metadata.getColumns()/ORDINAL_POSITION
Previous Message Miroslav Šulc 2007-02-17 11:01:09 Re: setArray