Overview

The UPPER() function returns a given string, an expression, or values in a column in all uppercase letters. The syntax of the function is illustrated below:

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.

  • We support Unicode for the UPPER() function.

Examples

#Case 1: Basic UPPER() function

The following basic query converts the given string in all uppercase alphabets:

SELECT UPPER('PostGreSQL');

The final output will be as follows:

+-------------+
| upper       |
+-------------+
| POSTGRESQL  |
+-------------+

#Case 2: UPPER() function using columns and CONCAT() function

Let’s see how the UPPER() function works using an example with columns. We have a table named personal_details containing employee’s id, first_name, last_name, and gender of a retail store:

CREATE TABLE personal_details (
  id int,
  first_name string,
  last_name string,
  gender string
);
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 above query will show the following 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        |
+-----+-------------+-------------+----------+

Let’s assume that:

  1. We want to convert employees’ first and last names with id numbers 1, 3, and 5 to all uppercase letters.

  2. Then, combine them using the CONCAT() function into one full_name column in uppercase.

It can be done using the following 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      |
+---------------------+