Re: atoi-like function: is there a better way to do this?

From: Chris Angelico <rosuav(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: atoi-like function: is there a better way to do this?
Date: 2012-03-05 05:08:24
Message-ID: CAPTjJmpTU+O_YzXP-Tr-PwxsfRfU3QjPzGV3RzKVTe0WhRRAbg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 5, 2012 at 3:15 PM, Tom Molesworth <tom(at)audioboundary(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-03-05 05:13:14 Re: atoi-like function: is there a better way to do this?
Previous Message Tom Molesworth 2012-03-05 04:15:26 Re: atoi-like function: is there a better way to do this?