Re: Changing the type of a column in an already populated

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: Brian Minton <bminton(at)efn(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Changing the type of a column in an already populated
Date: 2002-11-22 08:57:05
Message-ID: 139644578.1037959025@liza
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

--On Donnerstag, 21. November 2002 23:45 -0500 Brian Minton
<bminton(at)efn(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2002-11-22 09:21:08 Re: Migrating data from MSAccess
Previous Message Damjan Pipan 2002-11-22 08:56:32 Re: modifying new tuple on insert in c trigger