【发布时间】:2019-09-06 10:13:54
【问题描述】:
我想从一个嵌套了更多 JSON 的 JSON 中提取所有标题为“title2”的元素。我有在 MySQL 上运行的代码,但我无法将其转换为 Redshift。
JSON 结构:
{"master-title": [{"title": "a", "title2": "b"},{"title": "c", "title2: "d", "title3": "e"}], "master-title2": [{"title": "f", "title2": "g", "title3": "h"},{"title": "i", "title2": "j", "title3": "k"}]}
MySQL 查询(按需要工作):
select id
,json_extract(myJSON, '$**.title2')),0)
from myTable
MySQL 输出:
["b", "d","g","j"]
我的问题是,在 Redshift 上,我只能将路径具体定义为:
JSON_EXTRACT_PATH_TEXT(myJSON, 'master-title2',0,'title')
所以我只能得到一个元素而不是全部。
知道如何使用 Redshift 评估所有路径并获取 JSON 数组中具有相同“title2”的所有元素吗? (与 MySQL 中的输出相同)
提前谢谢你。
【问题讨论】:
标签: mysql arrays json path amazon-redshift