我正在尝试将exiftool
生成的JSON通过psql
有效插入到Postgresql中。似乎以某种方式使转义的单引号和转义的双引号无法正常工作。我不知道如何正确转义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.
有什么建议?
在数据库命令中转义单引号需要将其加倍:
test=> insert into test values ('{"a": 1, "b": "1'' 2\""}');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句