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