Re: changing column data types

From: ERIC Lawson - x52010 <eric(at)bioeng(dot)washington(dot)edu>
To: Derek <derek(dot)mailer(at)virgin(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: changing column data types
Date: 2001-02-21 16:50:22
Message-ID: Pine.LNX.4.21.0102210825220.32522-100000@arwen.bioeng.washington.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

What command did psql complain about, and what was psql's complaint
(supposing you're using psql)?

The general procedure, AFAIK, if you don't care about getting rid of the
old column, is to use ALTER TABLE tablename ADD COLUMN columnname
DATATYPE, then UPDATE tablename SET newcolumn=oldcolumn WHERE whatever,
'casting' the data from the old column as needed and appropriate.

This seems comparatively painless to me. It gets more painful when the
lack of an ALTER TABLE tablename DROP COLUMN columnname is felt, but even
then, using pg_dump -s along with a text editor ain't no more than a
mosquito bite.

On Wed, 21 Feb 2001, Derek wrote:

> Excuse my ignorance, but I'm used to MySQL and I'm having problems trying to
> convert a few columns from varchar to numeric. I attempted to get around
> the problem by creating a new numeric column, but pgsql didn't like it when
> I tried to copy the varchar column info into the numeric one.
>
> Is there a painless way of changing a column type?
>
> Thanks in advance for any help offered
>
> Derek
>

--

James Eric Lawson
Research Publications Editor III
National Simulation Resource

eric(at)bioeng(dot)washington(dot)edu

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Everyday language is a part of the human organism and is no less
complicated than it. - Ludwig Wittgenstein (1889-1951) [Tractatus
Logico-Philosophicus, 1921]

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message ERIC Lawson - x52010 2001-02-21 17:05:23 Re: copying tables
Previous Message Derek 2001-02-21 15:45:03 changing column data types

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff MacDonald 2001-02-21 17:39:04 pl/Perl
Previous Message Josh Berkus 2001-02-21 16:42:07 two tables - foreign keys referring to each other...]