2016-05-31 11 views
0

これを参照すると、複数の区切り文字に9.4スプリットコラムSOpostgresの新しい列

Postgres unnest

4列に2つの区切り文字に基づいて列を分割する方法はあります質問?

このデータが入っている列がある場合。

11-3-1-4 $72390.00 

は、どのように私はそれ

col1 col2 col3 col4 col5 
11  3  1  4  72390.00 

なるだろうプラス私は、元の列を保持すべき?

答えて

1

string_to_array()はこのために使用することができます。

select c1[1] as col1, 
     c1[2] as col2, 
     c1[3] as col3, 
     c1[4] as col4, 
     substr(col5, 2) as col5 
from (
    select string_to_array((string_to_array(the_column, ' '))[1], '-') as c1, 
      (string_to_array(the_column, ' '))[2] as col5 
    from the_table 
) t 
関連する問題