PostgreSQL – INITCAP Function

The initcap function in PostgreSQL database is used to capitalize the first letter of each word in a string, while converting all other letters to lowercase. It’s often used to format text in a more readable or proper case.

Here’s the syntax for the initcap function:

initcap(input_string)
  • input_string is the string that you want to capitalize.

The initcap function takes the input_string and returns a new string with the first letter of each word in uppercase and all other letters in lowercase.

Here’s an example of how to use the initcap function:

SELECT initcap('hello world');

In this example, the initcap function is used to capitalize the first letter of each word in the string 'hello world'. The result of this query will be 'Hello World'.

It’s important to note that initcap doesn’t consider certain characters (like spaces, punctuation, etc.) as word separators, so it will capitalize the first letter following these characters as well.

Here’s another example:

SELECT initcap('the quick brown-fox, jumps over the lazy dog');

The result of this query will be 'The Quick Brown-Fox, Jumps Over The Lazy Dog'.

Similar Posts