From: | Chris Angelico <rosuav(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to convert integer to string in functions |
Date: | 2012-03-20 08:31:09 |
Message-ID: | CAPTjJmq=spFtDTjHzco1KQ_fr0CtfYvjNuCPC1t4+gh_OTxJ-g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Mar 20, 2012 at 7:14 PM, Stefan Keller <sfkeller(at)gmail(dot)com> wrote:
> But this only works if the input is a clean list of number characters already!
> Anything other than this will issue an error:
>
> postgres=# SELECT '10'::int;
>
> After trying hard to cope with anything possibly as an input string I
> found this:
>
> postgres=# SELECT to_number('0'||mytextcolumn,
> '99999999999.000')::int FROM mytable;
I came across the same issue, specifically wanting semantics like C's
atoi function. Some discussion on this list turned up a few options.
Beginning of thread, including one possibility:
http://osdir.com/ml/postgresql-pgsql-general/2012-03/msg00090.html
Another well-researched option, with slightly different semantics:
http://osdir.com/ml/postgresql-pgsql-general/2012-03/msg00094.html
Hope that helps!
ChrisA
From | Date | Subject | |
---|---|---|---|
Next Message | Stefan Keller | 2012-03-20 08:48:31 | Re: How to convert integer to string in functions |
Previous Message | Stefan Keller | 2012-03-20 08:14:25 | Re: How to convert integer to string in functions |