找不到jsonb

编程入门 行业动态 更新时间:2024-10-26 16:22:09
本文介绍了找不到jsonb_array_elements时不返回行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用交叉联接对嵌套的json值进行嵌套,但是当未归档时,它不返回任何记录.下面使用左连接是否有解决方案?

I use cross join to unnest nested json values, but when filed not found it returns no record. is there a solution for the below using left join somehow?

create table json_example as select '{"id": "21397", "fields": { "labels": [] , "subtasks": [{"id": "10217"}] }}'::jsonb as value union all select '{"id": "21397", "fields": { "labels": [] , "subtasks" : [] }}'::jsonb

返回两行:

select * from json_example

以下仅返回一行:

select subtasks.value->>'id' from json_example h cross join jsonb_array_elements(value->'fields'->'subtasks') as subtasks

我该如何解决上述两个记录的问题?

how i can solve the above, problem to have both records?

推荐答案

您可以添加on true来使left join正常工作.

You may add on true for left join to work.

select subtasks->>'id' from json_example h left join jsonb_array_elements(value->'fields'->'subtasks') as subtasks on true

更多推荐

找不到jsonb

本文发布于:2023-10-29 03:22:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   jsonb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!