PostgreSQL CHR() Function
The PostgreSQL CHR() function returns character with the given code. For UTF8, this function treats the argument as a Unicode code point. For other multibyte encodings the argument must designate an ASCII character.
Syntax
CHR(number)
Parameters
number |
Required. Specify integer whose character values is to be retrieved. |
Return Value
Returns character with the given code.
Example 1:
The example below shows the usage of CHR() function.
SELECT CHR(72); Result: 'H' SELECT CHR(NULL); Result: NULL SELECT CHR('72'); Result: 'H'
Example 2:
Consider a database table called Sample with the following records:
Data | Numbers |
---|---|
Data1 | 67 |
Data2 | 64 |
Data3 | 84 |
Data4 | 66 |
Data5 | 35 |
Data6 | 100 |
The statement given below can be used to get the character given by the code values specified by column Numbers.
SELECT *, CHR(Numbers) AS CHR_Value FROM Sample;
The query will produce the following result:
Data | Numbers | CHR_Value |
---|---|---|
Data1 | 67 | C |
Data2 | 64 | @ |
Data3 | 84 | T |
Data4 | 66 | B |
Data5 | 35 | # |
Data6 | 100 | d |
❮ PostgreSQL Functions