Skip to main content
Documents
Basic SyntaxMath FunctionsDate FunctionsJSON FunctionsDatabasesTables & Schema ManagementString FunctionsTriggersIndexes

PostgreSQL UPPER

The PostgreSQL UPPER function is a string function used to convert all characters in a text string to uppercase. It is often utilized when case-insensitive comparisons or formatting are needed.

Usage

The UPPER function is used when you need to ensure that text is in a consistent uppercase format, which is useful for case-insensitive searches or standardizing data output.

UPPER(string)

In this syntax, string is the input text that you want to convert to uppercase.

Examples

1. Basic Uppercase Conversion

SELECT UPPER('hello world');

This example converts the string 'hello world' to 'HELLO WORLD'.

2. Uppercase Conversion on Table Column

SELECT UPPER(name)
FROM employees;

Here, the UPPER function is applied to the name column of the employees table, converting all names to uppercase.

3. Combining UPPER with Other Functions

SELECT UPPER(SUBSTRING(description, 1, 10))
FROM products;

In this example, UPPER is combined with SUBSTRING to convert the first ten characters of the description column from the products table to uppercase.

Tips and Best Practices

  • Use for case-insensitive searches. Combine UPPER with LIKE or = operator to perform case-insensitive queries.
  • Combine with other string functions. Use UPPER alongside functions like SUBSTRING or TRIM for more complex string manipulations.
  • Optimize for performance. Consider the performance impact when using UPPER on large datasets, as it can be computationally intensive. If performance becomes an issue, explore indexing strategies or consider alternative approaches.
  • Standardize data entry. Use UPPER to ensure consistent data entry standards, especially for fields like email addresses or user IDs.
  • Locale Consideration: The UPPER function's behavior can be influenced by the database's locale settings, which may affect character conversion for non-ASCII characters.
  • Error Handling: Be aware that UPPER will return NULL if the input string is NULL. Consider handling NULL values to avoid unexpected results.