甘草片
作者甘草片·2022-01-17 12:37
软件开发工程师·安天科技

一些不太常用的pg函数!特别适用各种开发

字数 497阅读 2329评论 0赞 2

1 string_agg(field,'分隔符') 字符串聚合

eg:
c1

    1
    2
    3

select string_agg(c1,',') from t1 group by c1
result :1,2,3

2 取出一个组字符串中最大最小的值

select GREATEST(33,4,3)
33
select LEAST(33,4,3)
3

3 regexp_split_to_table 把字符串转换成一列

select regexp_split_to_table(coalesce('/home/postgres/pg_basebackup.sh',''),E'\/') ;

regexp_split_to_table

home
postgres
pg_basebackup.sh

4 分割字符串 取出第几个部分

split_part(str,',',1)
selectsplit_part('A3332-22222222','-',1); - > A3332
selectsplit_part('A3332-22222222','-',2); - > 22222222

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

2

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广