特殊应用

最近更新时间: 2025-02-18 16:02:00

  • 多行变成单行。
  • 复制
    复制成功
postgres=# create table t_mulcol_tosimplecol(id int,mc text);
CREATE TABLE

postgres=# insert into t_mulcol_tosimplecol values(1,'TDSQL PG'),(2,'TDSQL PG');  
INSERT 0 2

postgres=# select array_to_string(array(select mc from t_mulcol_tosimplecol),',');
 array_to_string 
-----------------
 TDSQL PG,TDSQL PG
(1 row)
  • 一列变成多行。
  • 复制
    复制成功
postgres=# create table t_col_to_mulrow(id int,mc text);
CREATE TABLE

postgres=# insert into t_col_to_mulrow values(1,'TDSQL PG,TDSQL PG');  
INSERT 0 1

postgres=# select regexp_split_to_table((select mc from t_col_to_mulrow where id=1 limit 1), ',');

 regexp_split_to_table 
-----------------------
 TDSQL PG
 TDSQL PG
(2 rows)