September 19, 2023
Summary: The PostgreSQL CHR()
function converts an integer ASCII code to a character or a Unicode code point to a UTF8 character.
Table of Contents
Syntax
The following shows the syntax of the CHR()
function:
CHR(num)
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 which is corresponding 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:
SELECT
CHR(65),
CHR(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:
SELECT
CHR(937);
The output for the Unicode code point 937 is Ω, which is what we expected.
Remarks
To get ASCII code or Unicode code point of a character, 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.
See more
PostgreSQL Tutorial: String Functions
PostgreSQL Documentation: String Functions and Operators