I have a table in postgresql 14 like this one:
text classes
some string [food, drink]
another string [food, medicine, drink]
another random [car]
And I want to get this as output:
text class_1 class_2 class_3
some string food drink
another string food medicine drink
another random car
So I want to strip the []
off and explode each of the string into columns.
I am trying:
select text, replace(replace(unnest(string_to_array(classes, ',')), '[', ' '),']','') from tbl
but i am getting each of the classes in one line which duplicates the text columns
Also, is there any clean way to remove the []
?