如何将数据转换成给定的格式?
How to convert data into given format?
task_id json_data
task1 [ [160, "4d3a339c-68ba"], [15, "554fc01c-b5d2"] ]
我要把上面的图片改成下面的格式:
task_id area iiid
task1 160 "4d3a339c-68ba"
task1 15 "554fc01c-b5d2"
可以把json的内容变成数组的数组,然后unnest,然后把每个sub-array的第一个和第二个元素带进来:
select t.task_id, x.ar[0] area, x.ar[1] iiid
from mytable t
cross join unnest(cast(t.json_data as array(array(varchar)))) as x(ar)
task_id json_data
task1 [ [160, "4d3a339c-68ba"], [15, "554fc01c-b5d2"] ]
我要把上面的图片改成下面的格式:
task_id area iiid
task1 160 "4d3a339c-68ba"
task1 15 "554fc01c-b5d2"
可以把json的内容变成数组的数组,然后unnest,然后把每个sub-array的第一个和第二个元素带进来:
select t.task_id, x.ar[0] area, x.ar[1] iiid
from mytable t
cross join unnest(cast(t.json_data as array(array(varchar)))) as x(ar)