pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
datatype conversion on postgresql 7.4.1
2+ messages / 2 participants
[nested] [flat]

* datatype conversion on postgresql 7.4.1
@ 2005-05-22 11:29  Timo Roessner <timo.roessner@gmx.net>
  0 siblings, 1 reply; 2+ messages in thread

From: Timo Roessner @ 2005-05-22 11:29 UTC (permalink / raw)
  To: pgsql-sql

hi everybody,

i got the following problem:

i have a database running on a postgresqlserver version 7.4.1, in the 
database is a table with 4 columns containing
float-numbers. what i want to do now is,  to convert the type of those 
columns from float to numeric, because
i want to limit the positions after the decimal point to 2.

what works fine in v. 8:

either

alter table fragment alter column  x type numeric(15,2)

or

update fragment set x = round(x,2)

but both wont work with version 7.4.1!

when i look into the documentation it seems to say that in 7.4.1 round() 
can only round to a given number of positions after the decimal point 
when used with a numeric type, but not with floats!

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...

thx for any help in advance





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: datatype conversion on postgresql 7.4.1
@ 2005-05-24 07:45  Richard Huxton <dev@archonet.com>
  parent: Timo Roessner <timo.roessner@gmx.net>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2005-05-24 07:45 UTC (permalink / raw)
  To: Timo Roessner <timo.roessner@gmx.net>; +Cc: 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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-05-24 07:45 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-05-22 11:29 datatype conversion on postgresql 7.4.1 Timo Roessner <timo.roessner@gmx.net>
2005-05-24 07:45 ` Richard Huxton <dev@archonet.com>

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