From: Chuming Chen <chen@musc.edu>
To: Martin Fandel <martin.fandel@alphyra-evs.de>
Cc: pgsql-admin@postgresql.org
Subject: Re: change existing table definition
Date: Tue, 28 Jun 2005 13:26:56 -0400
Message-ID: <42C18860.1010906@musc.edu> (raw)
In-Reply-To: <1119974365.18693.16.camel@fandelm.ecommit.de>
References: <42C15044.4030407@musc.edu>
<1119974365.18693.16.camel@fandelm.ecommit.de>
Hi,
Thanks a lot for your quick reply and help. The following is what I find
from google. Will it work?
A quicker solution would be to use the pg_dump command
to dump the table, change the needed columns and restore
everything.
pg_dump -c -t <table name> <database> > <dumpfile>
psql <database> < <dumpfile>
Regards,
Chuming
Martin Fandel wrote:
>Aehm sorry. ALTER TABLE is not only in PostgreSQL 8 ;). Only the
>datatypes can be changed in postgres 8 (right?). I answered to fast.
>I'm sorry.
>
>CREATE TABLE newtable ( "bla" varchar(50));
>CREATE INDEX/TRIGGER/... (with different names as the production table)
>INSERT INTO newtable (select * from production);
>ALTER TABLE production RENAME TO old;
>ALTER TABLE newtable RENAME TO production;
>
>If this is working correctly, you can drop the old INDEXES and
>rename them.
>
>If its not working correctly
>
>ALTER TABLE production RENAME TO new;
>ALTER TABLE old RENAME TO production;
>
>and insert the different data (which is in the oldtable) into the
>production table.
>
>Greetings,
>Martin
>
>
>Am Dienstag, den 28.06.2005, 17:29 +0200 schrieb Martin Fandel:
>
>
>>Hi
>>
>>ALTER TABLE is only in PostgreSQL 8. But you can create a new table
>>with varchar(50) and copy the data from the existing into the new
>>table. How much relation_size has your table? Do you create the
>>dbsize-functions which are included in the contrib package?
>>
>>Best regards,
>>Martin
>>
>>Am Dienstag, den 28.06.2005, 10:39 -0400 schrieb Chuming Chen:
>>
>>
>>>Peter Eisentraut wrote:
>>>
>>>
>>>
>>>>Chuming Chen wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>How can I change the column definition of an existing table, ie. from
>>>>>varchar(30) to varchar(50)? Is there any way to add a new column to
>>>>>an existing table?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>The ALTER TABLE command can do all that. You need version 8.0 or later
>>>>for some functionality though.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>Is there another way to do it in 7.* ?
>>>
>>>---------------------------(end of broadcast)---------------------------
>>>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>>>
>>>
>
>
>
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: chen@musc.edu, martin.fandel@alphyra-evs.de
Subject: Re: change existing table definition
In-Reply-To: <42C18860.1010906@musc.edu>
References: <42C15044.4030407@musc.edu> <1119974365.18693.16.camel@fandelm.ecommit.de> <42C18860.1010906@musc.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox