Convert Column to Lowercase in PostgreSQL – LOWER()

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 PostgreSQL - LOWER() 1

 

 

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.

Convert Column to Lowercase in PostgreSQL - LOWER() 3

 

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:

Convert Column to Lowercase in PostgreSQL - LOWER() 4

 

 

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 Lowercase in PostgreSQL - LOWER() 5

 

 

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.

Convert Column to Lowercase in PostgreSQL - LOWER() 6

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:

Convert Column to Lowercase in PostgreSQL - LOWER() 7

 

 

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts