普通操作

  1. 更新多参数SQL
1
update table_a a set (col_a, col_b) = (select b.col_a, b.col_b from table_b b where a.col_c = b.col_c) where exists (select 1 from table_b b where a.col_c = b.col_c)
  1. 分组排序
1
select * from (select *, row_number() over(partition by col_a order by col_b) rn from table_a) t where rn = 1;
  1. 分组排序删除
1
delete from table_a where id in (select id from (select id, row_number() over(partition by col_a order by col_b) rn from table_a) t where rn != 1);

系统类

  1. 查看当前所有连接,连接个数
1
2
3
4
5
6
select * from pg_stat_activity;

select count(1) from pg_stat_activity;

# 查询最大连接数
show max_connections;