Sql 仅在字段不为null时提取json

Sql 仅在字段不为null时提取json,sql,arrays,json,postgresql,lateral-join,Sql,Arrays,Json,Postgresql,Lateral Join,我想从(可为空的)JSONB字段中提取一个键值。如果字段为空,我希望记录仍然存在于结果集中,但带有空字段 客户表格: id, name, phone_num, address 1, "john", 983, [ {"street":"23, johnson ave", "city":"Los Angeles", "state":"California", &

我想从(可为空的)JSONB字段中提取一个键值。如果字段为空,我希望记录仍然存在于结果集中,但带有空字段

客户
表格:

id, name, phone_num, address
1, "john", 983, [ {"street":"23, johnson ave", "city":"Los Angeles", "state":"California", "current":true}, {"street":"12, marigold drive", "city":"Davis", "state":"California", "current":false}]
2, "jane", 9389, null
3, "sally", 352, [ "street":"90, park ave", "city":"Los Angeles", "state":"California", "current":true} ]
当前PostgreSQL查询:

select id, name, phone_num, items.city
from customer, 
     jsonb_to_recordset(customer) as items(city str, current bool)
where items.current=true
它返回:

id, name, phone_num, city
1, "john", 983, "Los Angeles"
3, "sally", 352, "Los Angeles"
所需输出:

id, name, phone_num, city
1, "john", 983, "Los Angeles"
2, "jane", 9389, null
3, "sally", 352, "Los Angeles"

如何实现上述输出?

使用
左连接横向连接,而不是隐式横向连接:

select c.id, c.name, c.phone_num, i.city
from customer c
left join lateral jsonb_to_recordset(c.address) as i(city str, current bool)
    on i.current=true