w3resource logo
MySQL Tutorial

PostgreSQL CHR() function

CHR() function

The PostgreSQL chr function is used to return the corresponding character against the given code within the argument.



PostgreSQL Version: 9.3

Pictorial Presentation of PostgreSQL CHR() function

Pictorial presentation of PostgreSQL CHR() function

Example: PostgreSQL CHR() function:

In the example below, the chr function returns the character against the corresponding code.


SELECT chr(90) AS "Character of CODE(90)";

Sample Output:

 Character of CODE(90)
(1 row)

Example of PostgreSQL CHR() function using column:

Sample Table: employees

Here in the example, we want to make a query without using LEFT(), SUBSTRING() function. We want to find those employees who start their first_name with the letter 'A'. Here we have displayed three columns i.e. empoloyee_id, first_name and last_name.


SELECT employee_id,first_name,last_name 
FROM employees
WHERE chr(ascii(first_name))='A';

Sample Output:

 employee_id | first_name | last_name
         103 | Alexander  | Hunold
         115 | Alexander  | Khoo
         121 | Adam       | Fripp
         147 | Alberto    | Errazuriz
         158 | Allan      | McEwen
         167 | Amit       | Banda
         175 | Alyssa     | Hutton
         185 | Alexis     | Bull
         187 | Anthony    | Cabrio
         196 | Alana      | Walsh
(10 rows)

Amazon promo codes to get huge discounts for limited period (USA only).