如何将数组[" a"," b"," c"]插入测试?
function sort_by(field, reverse, primer) {
var key = primer ?
function (x) {
return primer(x[field])
} :
function (x) {
return x[field]
};
reverse = !reverse ? 1 : -1;
return function (a, b) {
a = new Date(key(a)), b = new Date(key(b));
return reverse * (a-b);
}
}
我试过
create table test( f json [] );
但是当我选择它时会显示转义反斜杠。 没有逃脱它根本不起作用。 (令牌" a"无效)
insert into test (f) values('{\"a\",\"b\",\"c\"}');
答案 0 :(得分:3)
我想你只想插入一个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\""}