【问题标题】:postgres 9.4 split column on multiple delimiters to new columnspostgres 9.4将多个分隔符上的列拆分为新列
【发布时间】:2016-05-31 06:26:57
【问题描述】:

参考这个 SO 问题

Postgres unnest

有没有办法将基于 2 个分隔符的列拆分为 4 列?

如果我有一列包含此数据。

11-3-1-4 $72390.00

我该怎么做呢

col1    col2    col3    col4    col5
11      3       1       4       72390.00

另外我应该保留原始列吗?

【问题讨论】:

    标签: sql postgresql postgresql-9.4


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多