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