"无法将数组解构为对象"

时间:2017-08-23 12:15:59

标签: json postgresql

我有以下查询

SELECT * FROM (
    SELECT * from "Table0"        
    UNION SELECT * from "Table1" 
    UNION SELECT * from "Table2" 
    UNION SELECT * from "Table3" 
    UNION SELECT * from "Table4" 
    UNION SELECT * from "Table5") as req 
    join lateral json_each_text(previewcontent::json) j on true where j.value like '%0.0'

PreviewContentjsonb字段。

但Postgres返回以下错误:

ERROR: cannot deconstruct an array as an object
SQL state: 22023

我不知道为什么。 这个请求几天前就已经开始了。

1 个答案:

答案 0 :(得分:0)

Postgres 9.6 +

来自数组:unnest。例如:SELECT unnest(ARRAY['my', 'nice', 'command'])

参考:https://www.postgresql.org/docs/9.6/static/functions-array.html

Postgres 10 +

来自json:json_array_elements_text。例如:SELECT json_array_elements_text('["my", "nice", "command"]'::json)

参考:https://www.postgresql.org/docs/current/static/functions-json.html