I created this PostgreSQL query while troubleshooting a problem that turned out to be due to non-printing characters in my strings:
with cte as ( select 'The character between the xes is evil: xx' as my_bad_string )
select substring( s.my_bad_string, n.i, 1) char_i
, ascii(substring( s.my_bad_string, n.i, 1)) ascii_char_i
from
cte as s
cross join (
select generate_series(1, length( 'The character between the xes is evil: xx' ))
) n(i)
It works. It helped me to find the evil character 141.
Question: what is a more elegant way to write this query so that my hard-coded string appears exactly once instead of twice?