Re: Casting Varchar to Numeric - Mailing list pgsql-general

From Andy Marden
Subject Re: Casting Varchar to Numeric
Date
Msg-id 000c01c17ddb$55394150$91d8fea9@marden1
Whole thread Raw
In response to Re: Casting Varchar to Numeric  (Jan Wieck <janwieck@yahoo.com>)
Responses Re: Casting Varchar to Numeric
List pgsql-general
The whole point is that someone should be able to pick up PostgreSQL and use it. All this rigmorole is not well
documented.What is 
wrong with the equivalent of Oracle's to_char and to_number? It works and hasn't caused anyone, to my knowledge,
sleeplessnights. 
Sure it's great re the extra types and ability to cast via different routes, but don't scare people off at the first
hurdle!This 
flexibility should be a bonus not a requirement.

Andy
----- Original Message -----
From: "Jan Wieck" <janwieck@yahoo.com>
To: "Martijn van Oosterhout" <kleptog@svana.org>
Cc: "Andy Marden" <amarden@usa.net>; <pgsql-general@postgresql.org>
Sent: Wednesday, December 05, 2001 10:09 PM
Subject: Re: [GENERAL] Casting Varchar to Numeric


> Martijn van Oosterhout wrote:
> > On Wed, Nov 28, 2001 at 04:30:00PM -0000, Andy Marden wrote:
> > > Well, I've finally sorted it out and can now convert text/varchar fields
> > > into numeric I cannot BELIEVE I've had to resort to such things.
> > >
> > > I've changed all my varchar fields to text and then applied this to them
> > > (column name is 'litre_amount'):
> >
> > <snip ugly conversion method>
> >
> > Does this work?
> >
> > select litre_amount::float::numeric;
>
>     Maybe  it  works,  but  with the step through float you loose
>     precision. In  the  old  days  where  the  type  input/output
>     functions wheren't protected, one was able to use
>
>         select numeric_in(textout(litre_amount)) from ...
>
>     Well,  some  thought  it'd not be such a good idea to let end
>     users muck around with C string pointers, and IIRC I was  one
>     of them.
>
>     But  there  are  still  the  internal casting capabilities of
>     PL/pgSQL.  What about
>
>         CREATE FUNCTION to_numeric ( text ) RETURNS numeric AS '
>         BEGIN
>             RETURN $1;
>         END;' LANGUAGE 'plpgsql';
>
>     Maybe this function is far too  overcomplicated  and  someone
>     might enhance the algorithm :-)
>
>
> Jan
>
> --
>
> #======================================================================#
> # It's easier to get forgiveness for being wrong than for being right. #
> # Let's break this rule - forgive me.                                  #
> #================================================== JanWieck@Yahoo.com #
>
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>


pgsql-general by date:

Previous
From: "Thomas T. Thai"
Date:
Subject: sum up rows of BITs
Next
From: "Tim Nelson"
Date:
Subject: Handling NULL dates in "copy from" statement