我正在尝试通过
给定这个表:
有什么建议吗?
psql
将由exiftool
生成的JSON插入到PostgreSQL中,该JSON似乎是有效的。 但是,转义的单引号和双引号似乎无法正常工作。我无法弄清楚如何正确转义json。出现问题的地方在于,psql不能正确处理单引号的转义,因为它会将\"发送到psql而不是查询中。给定这个表:
create table test (exif jsonb);
这些功能有效:
test=> insert into test values ('{"a": 1, "b": "2"}');
INSERT 0 1
test=> insert into test values ('{"a": 1, "b": "2\""}');
INSERT 0 1
test=> select * from test;
exif
----------------------
{"a": 1, "b": "2"}
{"a": 1, "b": "2\""}
但是这些并不
test=> insert into test values ('{"a": 1, "b": "1\' 2\""}');
Invalid command \""}');. Try \? for help.
test=> select '{"a": 1, "b": "1' 2\""}';
Invalid command \""}';. Try \? for help.
test=> select E'{"a": 1, "b": "1' 2\""}';
Invalid command \""}';. Try \? for help.
test=> select '{"a": 1, "b": "1\' 2\""}';
Invalid command \""}';. Try \? for help.
有什么建议吗?