Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id CF8C19FB402 for ; Sat, 17 Feb 2007 15:09:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 98984-01 for ; Sat, 17 Feb 2007 15:09:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id 75DF29FB3F0 for ; Sat, 17 Feb 2007 15:09:28 -0400 (AST) Received: (qmail 25126 invoked by uid 1112); 17 Feb 2007 19:09:25 -0000 Date: Sat, 17 Feb 2007 14:09:25 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: "j.random.programmer" cc: pgsql-jdbc@postgresql.org Subject: Re: Bug in metadata.getColumns()/ORDINAL_POSITION In-Reply-To: <421136.5291.qm@web32015.mail.mud.yahoo.com> Message-ID: References: <421136.5291.qm@web32015.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/83 X-Sequence-Number: 16639 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