如何将数组 ["a","b","c"] 插入到测试中?
create table test( f json [] );
我试过了
insert into test (f) values('{\"a\",\"b\",\"c\"}');
但是当我选择它时会显示转义反斜杠。 如果不转义,它根本不起作用。 ( token “a”无效)
select * from test;
f
----
{"\"a\"","\"b\"","\"c\""}
最佳答案
我想您只想插入一个 json 数组 (json
) 而不是一个 json 数组 (json[]
):
create table test (f json);
insert into test (f) values(to_json(array['a','b','c']));
select * from test;
f
---------------
["a","b","c"]
如果你想要一个 json 数组:
create table test (f json[]);
insert into test (f) values
(array[to_json('a'::text),to_json('b'::text),to_json('c'::text)]);
select * from test;
f
---------------------------
{"\"a\"","\"b\"","\"c\""}
关于json - 将 json 数组插入 postgres json [],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33696031/