pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: j.random.programmer <javadesigner@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bug in metadata.getColumns()/ORDINAL_POSITION
Date: Sat, 17 Feb 2007 14:09:25 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0702171404010.30813@leary.csoft.net> (raw)
In-Reply-To: <421136.5291.qm@web32015.mail.mud.yahoo.com>
References: <421136.5291.qm@web32015.mail.mud.yahoo.com>



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



view thread (5+ messages)  latest in thread

Message-ID: <Pine.BSO.4.64.0702171404010.30813@leary.csoft.net>
Permalink:  ../Pine.BSO.4.64.0702171404010.30813@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.64.0702171404010.30813@leary.csoft.net

 · 

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: books@ejurka.com, javadesigner@yahoo.com
  Subject: Re: Bug in metadata.getColumns()/ORDINAL_POSITION
  In-Reply-To: <Pine.BSO.4.64.0702171404010.30813@leary.csoft.net>
  References: <421136.5291.qm@web32015.mail.mud.yahoo.com> <Pine.BSO.4.64.0702171404010.30813@leary.csoft.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