通过使用jsonb_array_elements()函数jsonb从Postgres中提取数据数组,它给出了错误:
不能从标量中提取元素
我认为这是因为NULL在返回调用中,添加了NULL检查条件但不起作用.任何帮助赞赏.
select id ,
CASE
WHEN report IS NULL OR
(report->'stats_by_date') IS NULL OR
(report->'stats_by_date'-> 'date') IS NULL then to_json(0)::jsonb
ELSE jsonb_array_elements(report -> 'stats_by_date' -> 'date')
END AS Date
from factor_reports_table
Run Code Online (Sandbox Code Playgroud)
截断的json数组看起来像:
"stats_by_date":{"date":[16632,16633,16634,...],"imps":[2418,896,1005 ......],...}