String split of the column in postgresql

String split of the column in postgresql we will be using split_part() function. With the help of split_part () function we will be splitting the string column . Let’s see how to

  • Split the string of the column in postgresql

Syntax of split_part():

split_part(colname,delimiter,splitnumber)

We will be using states table

String split of the column in postgresql 1

 

String split of the column in postgresql

String split of the column in postgresql is accomplished by using split_part () function as shown below

select *,split_part(state_name,' ',1) as s_name, split_part(state_name,' ',2) as s_code  
from states

We have splitted state_name column into s_name and s_code which has state name and state code respectively.  So the resultant table will be

String split of the column in postgresql 2