PgSQL常用SQL语句汇总
总结整理在项目中常用的SQL语句:强制关闭链接,删除数据库;筛选某列,逗号拼接;
(1)强制关闭链接,删除数据库
代码语言:javascript复制select pg_terminate_backend(pg_stat_activity.pid)
from pg_stat_activity
where datname='testdb' and pid<>pg_backend_pid();
drop database testdb;
(2)筛选某列,逗号拼接:string_agg(列名,',')
代码语言:javascript复制select string_agg(bs_org_id,',') as bs_org_ids
from bs_org
where par_org_id ='100'
如:121,134,135,136