From: Heather Johnson <hjohnson@nypost.com>
To: Jodi Kanter <jkanter@virginia.edu>
To: Postgres Admin List <pgsql-admin@postgresql.org>
Subject: Re: adding fields
Date: Fri, 18 Jan 2002 10:21:11 -0500
Message-ID: <00cc01c1a033$c2df39b0$510b10ac@sephie> (raw)
References: <00a401c1a030$3dfd0130$de138f80@virginia.edu>
Hi Jodi--
No, you shouldn't have to go to that amount of trouble. Try this instead (change the name of the table, the default value, the column name, and the column type to suit your needs):
BEGIN WORK;
LOCK TABLE table_adding_stuff_to IN ACCESS EXCLUSIVE MODE;
ALTER TABLE table_adding_stuff_to ADD COLUMN new_column_name COLUMNTYPE;
ALTER TABLE table_adding_stuff_to ALTER COLUMN new_column_name SET DEFAULT 'default value';
COMMIT WORK;
Then you can do:
BEGIN WORK;
UPDATE table_adding_stuff_to SET new_column_name = 'default value';
COMMIT WORK;
Heather
----- Original Message -----
From: Jodi Kanter
To: Postgres Admin List
Sent: Friday, January 18, 2002 9:55 AM
Subject: [ADMIN] adding fields
I need to add a field to an existing table that contains a good amount of data. Do I need to drop table, recreate, and then reload data to do this? I cannot seem to find any documentation to say otherwise.
Thanks
Jodi
_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu
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: hjohnson@nypost.com, jkanter@virginia.edu
Subject: Re: adding fields
In-Reply-To: <00cc01c1a033$c2df39b0$510b10ac@sephie>
References: <00a401c1a030$3dfd0130$de138f80@virginia.edu> <00cc01c1a033$c2df39b0$510b10ac@sephie>
* 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