Reputation: 36726
I want to return the unicode values from the values of a column in PostgreSQL.
Is this possible? How I do?
Example:
"Renato" : U+0022 U+0052 U+0065 U+006E U+0061 U+0074 U+006F U+0022
I want to do this because I want to discover the Unicode from some symbols and punctuations to add to a conversion regex to replace these values to others.
Upvotes: 3
Views: 3218
Reputation: 125424
You can list a whole range at once without the need to hand feed characters to the query:
select i, chr(i)
from
generate_series(160, 255) s(i)
order by i
Upvotes: 0
Reputation: 657972
Get one Unicode code point:
SELECT ascii('ã')
Result:
227
More in the manual here. A quote:
For UTF8 returns the Unicode code point of the character.
Get Unicode code points for a string:
SELECT array_agg(t)
FROM (
SELECT ascii(regexp_split_to_table('Conceição', '')) AS t
) x
Use string_agg
instead if you want a text string as result. For it you have to cast the values to text.
Upvotes: 7