On Sat, 17 Feb 2007, Tom Lane wrote:
> "j.random.programmer" <javadesigner@yahoo.com> writes:
>> This is a quick followup to my earlier post. Upon
>> further
>> testing, this bug reliably and reproducably happens
>> when an "alter table" command is used on the database.
>
> So the problem is that it's returning pg_attribute.attnum without any
> consideration for earlier dropped columns. Not sure how expensive it'd
> be to get the current logical column number, though --- at a minimum one
> would have to select all the table's pg_attribute rows :-(
>
I've fixed this in CVS when running against 8.4 and later servers by using
the row_number window function as was suggested elsewhere:
http://archives.postgresql.org/pgsql-general/2009-11/msg01067.php
Kris Jurka