【发布时间】:2017-11-24 14:04:35
【问题描述】:
我目前有这个LEFT JOIN,它是更大选择的一部分
LEFT JOIN (
SELECT
tags_components.component_id,
array_to_json(array_agg(tags.*)) as tags
FROM tags_components
LEFT JOIN tags ON tags.id = tags_components.tag_id AND tags_components.component_name = 'contact'
GROUP BY tags_components.component_id
) AS tags ON tags.component_id = contact.id
如果组件已分配所有标签,则按预期工作。但是tags 数组的大小始终为COUNT(tags.*),因此对于没有任何标签的组件,使用null 填充。有没有办法过滤掉那些空值?我尝试了不同的方法,例如在数组上使用 json_strip_nulls 或 FILTER,但我没有得到正确的结果(JSON 数组只包含非空值)
【问题讨论】:
标签: arrays json postgresql postgresql-9.5