Re: datatype conversion on postgresql 7.4.1

From: Richard Huxton <dev(at)archonet(dot)com>
To: Timo Roessner <timo(dot)roessner(at)gmx(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: datatype conversion on postgresql 7.4.1
Date: 2005-05-24 07:45:46
Message-ID: 4292DBAA.7030408@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Timo Roessner wrote:
> and if i try something like:
>
> alter table fragment alter column x type numeric(15,2)
>
> i get an syntax error, so this seems to be no feature in 7.4.1 (didnt
> find anything like that in the docs too....)
>
> what can i do to solve this? there must be some way in postgresql 7.4.1,
> if there is no way to do that, i have to
> build up the whole database from scratch........there must be a way to
> convert float to numeric values in 7.4.1 ,
> but i dont have a single clue...

There isn't a way to directly convert the type of a column in 7.4.x but
you can duplicate the effect.

BEGIN;
ALTER TABLE fragment RENAME COLUMN x TO old_x;
ALTER TABLE fragment ADD COLUMN x numeric(10,2);
UPDATE fragment SET x = old_x;
ALTER TABLE fragment DROP COLUMN old_x;
COMMIT;

Make sure you check any functions/application code that might be
expecting floating-point rather than numeric before you do this.

Oh, and upgrade from 7.4.1 to 7.4.7 as soon as possible.
--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Szűcs Gábor 2005-05-24 10:39:04 Re: could not devise a query plan
Previous Message Achilleus Mantzios 2005-05-24 06:21:18 Re: ARRAY() returning NULL instead of ARRAY[] resp. {}