Re: Cast char to number - Mailing list pgsql-general

From Bill Moran
Subject Re: Cast char to number
Date
Msg-id 20100224170313.fce5161b.wmoran@potentialtech.com
Whole thread Raw
In response to Re: Cast char to number  (Raymond O'Donnell <rod@iol.ie>)
Responses Re: Cast char to number  (Richard Huxton <dev@archonet.com>)
List pgsql-general
In response to Raymond O'Donnell <rod@iol.ie>:

> On 24/02/2010 21:42, Christine Penner wrote:
> > This is what I did.
> >
> > set all blank columns to '0' because they were causing errors.
> > alter table T alter column a type integer using a::integer
> >
> > That worked perfectly.
>
> Glad you got sorted.
>
> Bill's advice upthread is worth taking on board - if you're in a
> position to do so, make sure that numbers are stored as numbers rather
> than text, and you'll save yourself all sorts of wacky grief.

As an aside, I feel that this is a natural part of software evolution.
No matter how carefully you try to plan, you end up with someone
saying, "this will be a serial number that will contain both numbers
and letters" ... so you make it a text type field.  Then, a year later
you find out that the serial number is really just a number, and you
actually want to be able to do math on it because you can find out
the year the part was designed by dividing by 1000 or something.

You make the best decisions you can based on the available information.
If you get it wrong, there's always ALTER TABLE :)

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: Cast char to number
Next
From: Tom Lane
Date:
Subject: Re: Curious plperl behavior