Re: Casting Varchar to Numeric

From: "Andy Marden" <amarden(at)usa(dot)net>
To: "Jan Wieck" <janwieck(at)yahoo(dot)com>, "Martijn van Oosterhout" <kleptog(at)svana(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Casting Varchar to Numeric
Date: 2001-12-05 22:22:30
Message-ID: 000c01c17ddb$55394150$91d8fea9@marden1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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, sleepless nights.
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(at)yahoo(dot)com>
To: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>
Cc: "Andy Marden" <amarden(at)usa(dot)net>; <pgsql-general(at)postgresql(dot)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(at)Yahoo(dot)com #
>
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2001-12-05 22:26:35 Re: DEBUG messages
Previous Message Thomas F. O'Connell 2001-12-05 22:19:50 VACUUM and performance after pg_dumpall