1
我试图将exiftool
生成的JSON通过psql
插入postgresql,这似乎有效。看起来不知何故,逃脱的单引号和逃脱的双引号不能正常工作。我无法弄清楚如何正确地逃避json。看来,在psql不处理单引号逃逸正确作为其启动的\”走出去psql的,而不是查询psql在字符串内插入带双引号的json
对于这个表
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.
有什么建议?
双引号源被转义,json规范说他们应该逃脱。 – ruckc
感谢@ruckc的跟进 –