postgresql将多条记录合并为一个字符或者反之

将多行记录转化为一个字符串,用array_to_string内置函数即可!

select array_to_string(array(

    select distinct name from tab where 1=1

),'-->') as strs;

将一个字符串转化为多行记录,用regexp_splite_to_table即可!

select regexp_splite_to_table('asd,qwe,qeq,ere,fds,ert',',') as id;

分割之后再转化为整数

select cast( regexp_splite_to_table('1,2,3,4,5,6',',') as integer) as id;

猜你喜欢

转载自blog.csdn.net/u011498933/article/details/79391219