To Convert column to uppercase in PostgreSQL we will be using upper() function. It’s a built-in string functions which convert a string to uppercase. Lets see below examples
- Convert string to uppercase using upper() function
- Convert column to uppercase in the PostgreSQL table using upper() function
- Convert string to uppercase using Translate() function
- Convert column to uppercase in the PostgreSQL table using Translate() function
String to Upper case using UPPER() Function:
The UPPER() function in PostgreSQL converts all characters in a string to uppercase.
Example:
SELECT UPPER('address')
OR
SELECT UPPER('AddrESS')
Output:
Convert column to uppercase in the PostgreSQL table using upper() function:
UPPER() function in PostgreSQL is straightforward and efficiently converts all characters to uppercase. In our example we are converting two columns in the table to upper case
We will be using Employeetbl table.
SELECT *, upper(first_name) AS first_name_upper, upper(last_name) AS last_name_upper FROM employeetbl;
In the above example we are converting both first name and last name into upper case with the help of upper() function.
Output:
String to Upper case using Translate() Function:
The Translate() function in PostgreSQL takes 3 arguments First Argument is the String that needs to converted into upper case , second argument is a to z in small case letters and third argument is A to Z in Capital Letters,
Example:
SELECT TRANSLATE('address','abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') as upper
OR
SELECT TRANSLATE ('AddrESS','abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') as upper
Output:
Convert column to uppercase in the PostgreSQL table using translate() function:
The TRANSLATE() function can be used to manually convert each uppercase letter to its corresponding uppercase letter.
We will be using Employeetbl table.
Translate() function in PostgreSQL takes 3 arguments
- First Argument is the String that needs to converted into upper case.
- Second argument is a to z in small case letters.
- Third argument is A to Z in Capital Letters
To convert the column to upper case
SELECT *,TRANSLATE(first_name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') as first_name_upper from employeetbl
In the above example we are converting first name into upper case with the help of Translate() function.
Output: