Skip to content

how to split a string in a column field value of a table to multiple rows in select query in postgresql

table1

I want to insert above ITEM to table2 as following manner

table2

so i have used

the problem is split_part() need to specify a postion index,so it only split and shows first positions charaters means,

So how i acheive above

Advertisement

Answer

You can convert the string to an array, then unnest that array:

If you want to exclude the empty elements (e.g. in the line 4 |||| you can use:

Online example

User contributions licensed under: CC BY-SA
6 People found this is helpful