簡體   English   中英

多個分隔符上的postgres 9.4拆分列到新列

[英]postgres 9.4 split column on multiple delimiters to new columns

引用此SO問題

巢巢

有沒有一種方法可以將基於2個定界符的列拆分為4列?

如果我有一列包含此數據。

11-3-1-4 $72390.00

我怎么做

col1    col2    col3    col4    col5
11      3       1       4       72390.00

另外,我應該保留原始列嗎?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM