Re: Changing the type of a column in an already populated - Mailing list pgsql-general

From Tino Wildenhain
Subject Re: Changing the type of a column in an already populated
Date
Msg-id 139644578.1037959025@liza
Whole thread Raw
In response to Re: Changing the type of a column in an already populated database.  (Brian Minton <bminton@efn.org>)
List pgsql-general
Hi,

--On Donnerstag, 21. November 2002 23:45 -0500 Brian Minton
<bminton@efn.org> wrote:

> David Pradier wrote:
>> Hi!
>>
>> I'd like to know if it is possible to change the type of a column to a
>> compatible one, in an already populated database.
>> For example, changing a column from varchar(20) to varchar(25) ?
>> I'm using postgresql 7.3rc1
>>
>> Thanks for your help.
>>
>> Best regards,
>> David
>
> dump the database, edit the dump file, and reload.  of course, this is
> annonying on live data, but it works

Its more easy with a temporary or short lifetime table:

create table temp_table
as select * from oldtable;

drop oldtable;
create oldtable ( ...);
insert into oldtable
 select * from temp_table;

You can cover this in a transcation and with luck nobody
will even notice it for the whole process :)
(Take care of referential integrity or stored functions as
they might reference a cached, e.g. OID based reference to
the old table)

Regards
Tino

pgsql-general by date:

Previous
From: "Shridhar Daithankar"
Date:
Subject: Re: PostgreSQL compilation with custom table name
Next
From: "Damjan Pipan"
Date:
Subject: Re: modifying new tuple on insert in c trigger