Extract the substring of the column in Postgresql

In order to extract the substring of the column in postgresql we use SUBSTRING() function. SUBSTRING() Function in postgresql gets the substring of given string. Let’s see how to

  • Get substring from string in postgresql using SUBSTRING() function.

Syntax:

SUBSTRING (string ,start_position , length )

We will be using states table.

Extract substring of column in postgresql 1

 

Get substring of the column in Postgresql

Substring of the column in postgresl is extracted using SUBSTRING() function

select *, substring(state_name,1,7) as State_name_new from states

So the resultant dataframe will be

Extract substring of column in postgresql 2