将 json 数组插入 postgres json []

use*_*578 3 postgresql json insert

如何将数组 ["a","b","c"] 插入到 test 中?

create table test( f json [] );
Run Code Online (Sandbox Code Playgroud)

我试过

insert into test (f) values('{\"a\",\"b\",\"c\"}');
Run Code Online (Sandbox Code Playgroud)

但是当我选择它时,会显示转义反斜杠。如果不逃避它根本不起作用。(令牌“a”无效)

select * from test;

f
----
{"\"a\"","\"b\"","\"c\""}
Run Code Online (Sandbox Code Playgroud)

Clo*_*eto 5

我想您只想插入一个 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"]
Run Code Online (Sandbox Code Playgroud)

如果你想要一个 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\""}
Run Code Online (Sandbox Code Playgroud)