开发者

Split a column value into two columns in a SELECT?

开发者 https://www.devze.com 2023-04-07 02:07 出处:网络
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.

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 in开发者_运维问答to an array but I do not know how to get it into two columns.


select split_part(one_column, ' ', 1) AS part1, 
       split_part(one_column, ' ', 2)  AS part2 ...
0

精彩评论

暂无评论...
验证码 换一张
取 消