From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | Chris Angelico <rosuav(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: atoi-like function: is there a better way to do this? |
Date: | 2012-03-05 05:13:14 |
Message-ID: | 8D183FF2-CCAA-4EDF-907D-B68786BA4C2F@yahoo.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mar 5, 2012, at 0:08, Chris Angelico <rosuav(at)gmail(dot)com> wrote:
> 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
>
>
0alpha999 -> 0
alpha999 -> 999
From | Date | Subject | |
---|---|---|---|
Next Message | Sam Wong | 2012-03-05 06:41:18 | SELECT FOR UPDATE could see commited trasaction partially. |
Previous Message | Chris Angelico | 2012-03-05 05:08:24 | Re: atoi-like function: is there a better way to do this? |