Re: opposite of chr(int) - Mailing list pgsql-novice

From Merlin Moncure
Subject Re: opposite of chr(int)
Date
Msg-id CAHyXU0z0D63pGODHpBn7gt5fkWLxRYGAZG=UhJTMOvTxaCzK1Q@mail.gmail.com
Whole thread Raw
In response to opposite of chr(int)  (Henry Drexler <alonup8tb@gmail.com>)
List pgsql-novice
On Thu, Oct 6, 2011 at 2:42 PM, Henry Drexler <alonup8tb@gmail.com> wrote:
> Looking at the string functions on:
> http://www.postgresql.org/docs/9.0/static/functions-string.html
> I only see chr(int) and not something like int(chr).
> reading through the others on that page i do not see a int(chr)
> the goal is to tell whether or not a character in a string is an integer or
> not
> my current workaround is this:
> select
> case
> when substring('wallawa9kl',8,1) = '0' then 'true'
> when substring('wallawa9kl',8,1) = '1' then 'true'
> when substring('wallawa9kl',8,1) = '2' then 'true'
> when substring('wallawa9kl',8,1) = '3' then 'true'
> when substring('wallawa9kl',8,1) = '4' then 'true'
> when substring('wallawa9kl',8,1) = '5' then 'true'
> when substring('wallawa9kl',8,1) = '6' then 'true'
> when substring('wallawa9kl',8,1) = '7' then 'true'
> when substring('wallawa9kl',8,1) = '8' then 'true'
> when substring('wallawa9kl',8,1) = '9' then 'true'
> else 'false'
> end

I think the regex approach is better, but for posterity there is a
reverse of chr() function -- ascii();
postgres=# select ascii('C');
 ascii
-------
    67
(1 row)

merlin

pgsql-novice by date:

Previous
From: Henry Drexler
Date:
Subject: Re: opposite of chr(int)
Next
From: Henry Drexler
Date:
Subject: Re: opposite of chr(int)