2

If you see this link

Its all about unicode code range

example :

U+0644  ل   d9 84   ARABIC LETTER LAM

In PostgreSQL its easy to get hex value :

select encode('ل','hex')

it will return the hex value, d9 84.

but how to get the unicode code point ?

Thanks

1 Answer 1

1

If your input string is in UTF-8, you can use the ascii function:

ascii(string) int

ASCII code of the first character of the argument. For UTF8 returns the Unicode code point of the character. For other multibyte encodings. the argument must be a strictly ASCII character.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried select ascii('ل')::int but the result is '1604', not 644. Thanks
1604 is the decimal representation of the hexadecimal value 0x644 - if you want the hexadecimal value, run to_hex(ascii('ل')).
Hi Andres i have new problem using running this query select decode(to_hex(ascii('ل')::int),'hex'); i got error "ERROR: invalid hexadecimal data: odd number of digits"
Hmm, why would you want to do that? It seems backwards, as you already have a character?
@Thessa, if you want to reverse the process, you can use chr(), e.g. chr(1604) will give 'ل'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.