Re: how can we change definition of a table once created? - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: how can we change definition of a table once created?
Date
Msg-id Pine.BSF.4.21.0107082343100.86282-100000@megazone23.bigpanda.com
Whole thread Raw
In response to how can we change definition of a table once created?  (Bhuvan A <bhuvanbk@yahoo.com>)
List pgsql-sql
On Mon, 9 Jul 2001, Bhuvan A wrote:

> can any one say how can we change the table definition once
> created?
> 
> say, we have a table with 1000s of records. if one needs
> to change the data type of particular column or if he
> needs to change the width of a column what should be
> done? 
> 
> As of now, i am copying the data to a file(COPY COMMAND) and
> creating a new table after deleting the old one and copying
> the content of that file to the new table. 
> 
> is it the only way to do it?

Not quite.  Right now, you will need to make a new table, but
you can use alter table rename and insert ... select to make your
life a little easier... Something like:

create table new ... ;
insert into new (...) select ... from old;
alter table old rename to old_backup;
alter table new rename to old;
(drop old_backup when you're sure it's safe)



pgsql-sql by date:

Previous
From: Bhuvan A
Date:
Subject: how can we change definition of a table once created?
Next
From: Alvar Freude
Date:
Subject: Returning multiple Rows from PL/pgSQL-Function