Re: atoi-like function: is there a better way to do this? - Mailing list pgsql-general

From Chris Angelico
Subject Re: atoi-like function: is there a better way to do this?
Date
Msg-id CAPTjJmpTU+O_YzXP-Tr-PwxsfRfU3QjPzGV3RzKVTe0WhRRAbg@mail.gmail.com
Whole thread Raw
In response to Re: atoi-like function: is there a better way to do this?  (Tom Molesworth <tom@audioboundary.com>)
Responses Re: atoi-like function: is there a better way to do this?  (David Johnston <polobo@yahoo.com>)
Re: atoi-like function: is there a better way to do this?  (Tom Molesworth <tom@audioboundary.com>)
List pgsql-general
On Mon, Mar 5, 2012 at 3:15 PM, Tom Molesworth <tom@audioboundary.com> wrote:
> Can you use to_number() here? It sounds like something along the lines of
> cast(to_number('0' || field::varchar, '999999999.') as int) might give the
> behaviour you're after, and a quick test seems to indicate that it's about
> 4x faster than the original function:

I looked at to_number but it seems to find digits anywhere inside the
field - to_number('12.34','99999') returns 1234, but I want it to stop
at the decimal.

Nice trick with prepending a zero though - I didn't think of that.
That may save some hassle!

ChrisA

pgsql-general by date:

Previous
From: Tom Molesworth
Date:
Subject: Re: atoi-like function: is there a better way to do this?
Next
From: David Johnston
Date:
Subject: Re: atoi-like function: is there a better way to do this?