19

I have a string value in a varchar column. It is a string that has two parts. Splitting it before it hits the database is not an option.

The column's values look like this:

one_column:
'part1 part2'
'part1 part2'

So what I want is a a result set that looks like:

col1,col2:
part1,part2
part1,part2

How can I do this in a SELECT statement? I found a pgsql function to split the string into an array but I do not know how to get it into two columns.

NJ.
  • 2,155
  • 6
  • 26
  • 35

1 Answers1

39
select split_part(one_column, ' ', 1) AS part1, 
       split_part(one_column, ' ', 2)  AS part2 ...
Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
  • Worked, but I needed to give the columns names to avoid an error: `SELECT split_part(one_column, ' ', 1) AS part1, split_part(one_column, ' ', 2) AS part2 ...` – avivr Sep 02 '13 at 05:19