PostgreSQL 9.3:将一列拆分为多列

PostgreSQL 9.3: Split one column into multiple

我想将下面给出的示例中 colb 的一列拆分为两列 像 column1column2.

我有一个包含两列的 table:

示例:

create table t3
(
    cola varchar,
    colb varchar
);

插入:

insert into t3 values('D1','2021to123'),
                     ('D2','112to24201'),
                     ('D3','51to201');

我想将 colb 值分成两列,如以下预期结果:

预期结果

cola      column1        column2
---------------------------------
D1        2021           123
D2        112            24201
D3        51             201
select cola
      ,split_part(colb, 'to', 1) col1
      ,split_part(colb, 'to', 2) col2 
from t3

引自 PostgreSQL 文档:

split_part(string text, delimiter text, field int)

Split string on delimiter and return the given field (counting from one)