PostgreSQL CHR() Function
The PostgreSQL CHR()
function converts an integer ASCII code to a character or a Unicode code point to a UTF8 character.
Syntax
The following shows the syntax of the CHR()
function:
Arguments
The CHR()
function requires one argument:
1) num
The num argument is an integer that is converted to the corresponding ASCII code.
It could be a Unicode code point which is converted to a UTF8 character.
Return Value
The CHR()
function returns a character that corresponds the the ASCII code value or Unicode code point.
Examples
The following example shows how to use the CHR()
function to get the characters whose ASCII code value is 65 and 97:
The query returns character A for 65 and a for 97:
Here is an example of getting the UTF8 character based on the Unicode code point 937:
The output for the Unicode code point 937 is Ω, which is what we expected.
Remarks
To get the ASCII code or UTF-8 character of an integer, you use the ASCII()
function.
In this tutorial, you have learned how to use the PostgreSQL CHR()
function to get the character based on its ASCII value or Unicode code point.