PostgreSQL CHR() function
CHR() function
The PostgreSQL chr function is used to return the corresponding character against the given code within the argument.
Syntax:
chr(number)
PostgreSQL Version: 9.3
Pictorial Presentation of PostgreSQL CHR() function

Example: PostgreSQL CHR() function:
In the example below, the chr function returns the character against the corresponding code.
Code:
SELECT chr(90) AS "Character of CODE(90)";
Sample Output:
Character of CODE(90) ----------------------- Z (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.
Code:
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)
Previous: BTRIM function
Next: CONCAT function
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook