这很好地说明了这个问题:
当b列是文本类型而不是数组类型时,将执行以下操作:
select *
from json_to_record('{"a":1,"b":["hello", "There"],"c":"bar"}')
as x(a int, b text, d text);
a | b | d
---+--------------------+---
1 | ["hello", "There"] |
但是,如果我将b
列定义为数组,则会出现此错误:
select *
from json_to_record('{"a":1,"b":["hello", "There"],"c":"bar"}')
as x(a int, b text[], d text)
ERROR: malformed array literal: "["hello", "There"]"
DETAIL: "[" must introduce explicitly-specified array dimensions.
如何说服/强制json_to_record
(或json_populate_record
)将JSON数组转换为目标列类型的Postgres数组?