我在名为EVENTS的列下有一个名为flow_flowrun的表和一个json对象数组,如下所示:
[{"msg": {"urn": "tel:+1238948372", "text": "Would you like to JOIN, reply now", "uuid": "34567a-a634-4c1d-a0a5-56788", "channel": {"name": "*56789", "uuid": "b5bc6e6c-ad18-493f-b28f-744627e739f7"}}, "type": "msg_created", "step_uuid": "a4fg6hh-9419-43a4-tgdv-39a4edc78d69", "created_on": "2015-09-21T06:10:12.217880+00:00"}]
[{"msg": {"urn": "tel:+1294472830", "text": "Hello, how do you feel today", "uuid": "533457-693d-4d67-833c-0d53e7e0ff98", "channel": {"name": "*12345", "uuid": "b5bc6e6c-ad18-493f-b28f-744627e739f7"}}, "type": "msg_created", "step_uuid": "4556763-1f5b-40a4-a29d-5fb1103f4666", "created_on": "2014-02-08T06:04:57.823739+00:00"}]
我想运行一个仅显示“文本”输出的查询。 因此输出应如下所示:
消息 您想加入,立即回复 你好,你今天感觉如何
以此类推...
我没有运气尝试过以下内容:
SELECT jsonb_array_elements(fr.events->'msg'->'text') elem
FROM flows_flowrun fr
SELECT fr.EVENTS ->>'text'
from flows_flowrun fr
感谢您的期待。
运行上述查询时,没有任何结果。
答案 0 :(得分:0)
您需要先扩展数组并访问该数组的成员:
SELECT jsonb_array_elements(events)->'msg'->>'text'
FROM flows_flowrun fr