upper
The upper() function returns a given string, an expression, or values in a column in all uppercase letters:
UPPER(string)
It accepts input as a string and returns text in uppercase letters.
Special Case:
-
If characters in the input are not of type string, they remain unaffected by the
upper()function. -
Unicode is supported for the
upper()function.
Examples
Basic upper() function
This basic query converts the given string to all uppercase letters:
SELECT UPPER('PostGreSQL');
The query returns:
+-------------+
| upper |
+-------------+
| POSTGRESQL |
+-------------+
upper() function using columns and concat() function
This example shows how the upper() function works with columns. A table named personal_details contains employee’s id, first_name, last_name, and gender of a retail store:
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;
The query returns:
+-----+-------------+-------------+----------+
| 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 employees' first and last names with id numbers 1, 3, and 5 to all uppercase letters.
-
Then, combine them using the
concat()function into one full_name column in uppercase.Use this query:
SELECT CONCAT (UPPER(first_name),' ', UPPER(last_name)) as full_name FROM personal_details where id in (1, 3, 5);The output displays the first and last names of employees with the specified ids in uppercase letters:
+---------------------+ | full_name | +---------------------+ | MARK WHEELER | | JANE HOPPER | | LUCAS SINCLAIR | +---------------------+