PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

PostgreSQL INITCAP() Function



The PostgreSQL INITCAP() function converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters. If there are characters in the string that are not letters, they will be unaffected by this function.

Syntax

INITCAP(string)

Parameters

string Required. Specify the string to convert.

Return Value

Returns the string with first letter of each word to upper case and the rest to lower case.

Example 1:

The example below shows the usage of INITCAP() function.

SELECT INITCAP('Learning PostgreSQL is FUN!');
Result: 'Learning Postgresql Is Fun!'

SELECT INITCAP('PostgreSQL tutorial');
Result: 'Postgresql Tutorial'

Example 2:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1Johnlondon253000
2Marrynew york242750
3Joparis272800
4Kimamsterdam303100
5Rameshnew delhi283000
6Huangbeijing282800

The query given below is used to convert the City column values using this function.

SELECT *, 
INITCAP(City) AS INITCAP_Value 
FROM Employee;

The query will produce the following result:

EmpIDNameCityAgeINITCAP_Value
1Johnlondon25London
2Marrynew york24New York
3Joparis27Paris
4Kimamsterdam30Amsterdam
5Rameshnew delhi28New Delhi
6Huangbeijing28Beijing

❮ PostgreSQL Functions