1. select count(*) from A,统计所有数据包括null数据,这里会使用到聚合索引,如果判断聚合索引可以加快速度.
2. select count(a) from A,这里统计a列数据,除去null数据,如果select count(1) from a,之类的参数非表A列统
计所有数据.
3. select * from A where a = any (array(select b from B))这种比较array和scalar数据,也可以这样做:
select * from A where a = any ((select array(select b from B))::varchar[]) .
或select array(select a from A) <@ Array[1,2,3]
或:select (select array_agg(a) from A) <@ Array[1,3]
array的还原时unnest函数如:select unnest(Array[1,3])