pg 多列合并一列
下面是正常的查询多条数据,如果我要合并成列怎么办。
其实pg有自带的array_to_string函数 ,但是写法稍微有点麻烦,但是可以根据array_to_string函数自定义一个函数去简化写法。
CREATE AGGREGATE group_concat(anyelement)(
sfunc = array_append,
stype = anyarray,
initcond = '{}'
);
然后使用函数去指定字符串去分割就行了
下面是正常的查询多条数据,如果我要合并成列怎么办。
其实pg有自带的array_to_string函数 ,但是写法稍微有点麻烦,但是可以根据array_to_string函数自定义一个函数去简化写法。
CREATE AGGREGATE group_concat(anyelement)(
sfunc = array_append,
stype = anyarray,
initcond = '{}'
);
然后使用函数去指定字符串去分割就行了