Table definition changes when a row is dropped and recreated

From: "deep (dot)(dot)(dot)" <walter(dot)mitty(dot)esq(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Table definition changes when a row is dropped and recreated
Date: 2006-12-05 06:42:02
Message-ID: 331363f40612042242v6e8adcf4r4cdab8d96d220497@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi everyone,

I have a java app using pgsql 7.3 on unix platform where the latest
version of the app updates the width of a row in a table as a part of
upgrade. Since there is no straightforward 'modify' clause in
Postgresql 7.3, we're using

alter table ... add new_column type (width);
update ... set new_column=old_column;
alter table... drop old_column;

After running this sql as a part of upgrade script, the table
definition changes in database, in that the widened column gets pushed
to the end of the definition (as can be seen through \d table_name
command). This is making the insert queries fail which were designed
with the original table definition in mind.

Assuming there is no way to know whether the insert command is running
before or after upgrade (from within the database handler part of the
app, I mean), how do we solve this problem? Backup data, Drop the
table and create it again? In that case, what happens to the indexes
and constraints?

Thanks in advance,
Walter

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ronin 2006-12-05 06:43:21 Re: pgsql bug found?
Previous Message Michael Glaesemann 2006-12-05 05:07:39 Re: PG Admin