PostgreSQL Letter Case Functions With Practical Examples

PostgreSQL offers some built-in functions, such as LOWER(), INITCAP(), or UPPER(), to alter a string to lowercase, proper case(the first letter of every word would be capital), and uppercase, respectively. All these functions accept a string expression, table values, etc., as an argument and convert them to the respective case.

This post will present detailed knowledge about the Postgres letter case functions with the help of different examples. So, let’s begin.

How to Use the LOWER() Function in Postgres?

Use the Postgres LOWER() function to convert a string, column value, or an expression to lowercase. The below snippet will demonstrate the syntax of the LOWER() case function:

LOWER(string_expression | column_values);

Let’s consider the below example to get a profound knowledge of the Postgres LOWER() function.

Example #1: How to Convert a String in Lowercase?

Let’s pass a string to the LOWER() function to see how the LOWER() function works in Postgres:

SELECT LOWER('COMMANDPROMPT.COM');
img

The output shows that the LOWER() function converted the given string to the lower case.

Example #2: How to Use the LOWER() Function on the Table’s Data in Postgres?

Let’s execute the below statement to see the article_details table:

SELECT * FROM article_details;
img

We will use the LOWER() function to convert the values of the article_title column to the lower case:

SELECT LOWER(article_title)
FROM article_details;
img

The output shows that the LOWER() function successfully converted the column’s values to the lower case.

How Does the INITCAP() Function Work in Postgres?

Use the Postgres INITCAP() function to convert a string_expression or column value to the Proper/title case. The syntax of the Postgres INITCAP() function will be as follows:

INITCAP(string_expression | column_values);

Example #1: How to Convert a Function in Title Case?

The below snippet illustrates the working of the Postgres INITCAP() function:

SELECT INITCAP('welcome to commandprompt.com');
img

The INITCAP() function succeeded in converting the specified string into the proper case.

Example #2: How to Use the INITCAP() Function on the Table’s Data in Postgres?

This example explains how to use the INITCAP() function on the Table’s Data:

SELECT INITCAP(article_title)
FROM article_details;
img

This way, you can use the INITCAP() function on the table’s data.

How Does the UPPER() Function Work in Postgres?

Use the Postgres UPPER() function to convert a string_expression or column value to the upper case. Following will be the syntax of the UPPER() function in Postgres:

UPPER(string_expression | column_values);

Example #1: How to Convert a String in Uppercase?

The below snippet demonstrates the working of the Postgres UPPER() function:

SELECT UPPER('welcome to commandprompt.com');
img

The UPPER() function converts the user-specified string into the uppercase.

Example #2: How to Use the UPPER() Function on the Table’s Data in Postgres?

Let’s understand how to use the UPPER() function on the Table’s Data:

SELECT UPPER(article_title)
FROM article_details;
img

The output authenticates the working of the UPPER() function.

Conclusion

PostgreSQL provides various functions, such as LOWER(), INITCAP(), or UPPER(), to alter a string to lowercase, proper case, and uppercase, respectively. All these functions accept a string expression, table values, etc., as an argument and convert them to the respective case, i.e., uppercase, lowercase, proper case. This write-up explained the working of letter case functions with practical examples.