Re: how can we change definition of a table once created?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Bhuvan A <bhuvanbk(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: how can we change definition of a table once created?
Date: 2001-07-09 06:46:03
Message-ID: Pine.BSF.4.21.0107082343100.86282-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alvar Freude 2001-07-09 09:53:18 Returning multiple Rows from PL/pgSQL-Function
Previous Message Bhuvan A 2001-07-09 06:03:44 how can we change definition of a table once created?