lower
The lower() function returns a given string, an expression, or values in a column in all lowercase letters. The syntax of the function is:
LOWER(string)
It accepts input as a string and returns the text in the lowercase alphabet.
Special Cases: If there are characters in the input which are not of type string, they remain unaffected by the `lower()`function.
|
Unicode is supported so that the ß is equivalent to the string ss. |
Examples
Basic lower() function
This basic query shows how to convert the given string in all lowercase alphabets:
SELECT LOWER('PostGreSQL');
The query returns:
+------------+
| lower |
+------------+
| postgresql |
+------------+
lower() function using columns
This example shows how the lower() function works with columns. The personal_details table contains columns id, first_name, last_name, and gender of retail store employees.
CREATE TABLE personal_details (
id int,
first_name text,
last_name text,
gender text
);
INSERT INTO personal_details
(id, first_name, last_name, gender)
VALUES
(1,'Mark','Wheeler','M'),
(2,'Tom','Hanks','M'),
(3,'Jane','Hopper','F'),
(4,'Emily','Byers','F'),
(5,'Lucas','Sinclair','M');
SELECT * FROM personal_details;
This query shows the table:
+-----+-------------+-------------+----------+
| id | first_name | last_name | gender |
+-----+-------------+-------------+----------+
| 1 | Mark | Wheeler | M |
| 2 | Tom | Hanks | M |
| 3 | Jane | Hopper | F |
| 4 | Emily | Byers | F |
| 5 | Lucas | Sinclair | M |
+-----+-------------+-------------+----------+
Assume that the goal is to convert the first and last names of employees with id numbers 2, 4, and 5 to all lowercase letters:
SELECT first_name,last_name,LOWER(first_name),LOWER(last_name)
FROM personal_details
where id in (2, 4, 5);
The output displays the first and last names of employees with the specified ids in lowercase letters:
+------------+-------------+----------+----------+
| first_name | last_name | lower | lower |
+------------+-------------+----------+----------+
| Tom | Hanks | tom | hanks |
| Emily | Byers | emily | byers |
| Lucas | Sinclair | lucas | sinclair |
+------------+-------------+----------+----------+