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

From Gary Chambers
Subject Re: opposite of chr(int)
Date
Msg-id alpine.DEB.2.00.1110061604420.30299@lollipop.garychambers.com
Whole thread Raw
In response to opposite of chr(int)  (Henry Drexler <alonup8tb@gmail.com>)
Responses Re: opposite of chr(int)  (Henry Drexler <alonup8tb@gmail.com>)
List pgsql-novice
Henry,

> 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

> just wondering if there is something more compact or if this is an okay
> workaround solution.

How about:

CREATE OR REPLACE FUNCTION has_digit(text)
  RETURNS boolean
  LANGUAGE sql
AS $function$
select case when substring($1, '\d') is not null then true
else false
end
$function$

-- Gary Chambers

pgsql-novice by date:

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