pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: scott.marlowe <scott.marlowe@ihs.com>
To: David <de4@kent.ac.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: Alter table
Date: Wed, 10 Mar 2004 10:55:47 -0700 (MST)
Message-ID: <Pine.LNX.4.33.0403101052100.10418-100000@css120.ihs.com> (raw)
In-Reply-To: <006801c406c0$da8fef50$42660c81@ad.kent.ac.uk>

On Wed, 10 Mar 2004, David wrote:

> Ok another very newbie question. How can i change the data type a column can
> accept? at the moment it will only take character(7) i want to change it to
> varchar(30), but i cant figure how, ideas?

While there are ways to tinker with the system catalogs to change between 
different text types / lengths, none of these are "officially supported" 
and may well screw up your database if you do something wrong.  I believe 
the archives likely have this question over and over in them.

The proper way to do this is to make a new column, put the old column in 
it, and then drop the old column:

create table test (a char(7));
insert a few thousand lines to test...;
begin;
alter table test add column b varchar(30);
update test set b=a;
alter table test drop column a;
commit; (or rollback; should things go horribly wrong...)
vacuum full test;





view thread (22+ messages)  latest in thread

Message-ID: <Pine.LNX.4.33.0403101052100.10418-100000@css120.ihs.com>
Permalink:  ../Pine.LNX.4.33.0403101052100.10418-100000@css120.ihs.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.33.0403101052100.10418-100000@css120.ihs.com

 · 

reply

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-sql@postgresql.org
  Cc: scott.marlowe@ihs.com, de4@kent.ac.uk
  Subject: Re: Alter table
  In-Reply-To: <Pine.LNX.4.33.0403101052100.10418-100000@css120.ihs.com>
  References: <006801c406c0$da8fef50$42660c81@ad.kent.ac.uk> <Pine.LNX.4.33.0403101052100.10418-100000@css120.ihs.com>

* 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