Postgresql 当没有输入行时,让数组_agg()不返回任何行
当没有行时,函数array_agg返回null。我如何修改它,以便不返回任何行?例如,以以下简单查询为例:Postgresql 当没有输入行时,让数组_agg()不返回任何行,postgresql,Postgresql,当没有行时,函数array_agg返回null。我如何修改它,以便不返回任何行?例如,以以下简单查询为例: select array_agg(country) from country where false 这将返回一个值为null的行。我不希望返回任何行。使用HAVING子句删除空数组: [local] #= select array_agg(1) from a where false; ┌───────────┐ │ array_agg │ ├───────────┤ │ (nul
select array_agg(country)
from country
where false
这将返回一个值为null的行。我不希望返回任何行。使用HAVING子句删除空数组:
[local] #= select array_agg(1) from a where false;
┌───────────┐
│ array_agg │
├───────────┤
│ (null) │
└───────────┘
(1 row)
[local] #= select array_agg(1) from a where false having array_agg(1) <> '{}';
┌───────────┐
│ array_agg │
├───────────┤
└───────────┘
(0 rows)