【发布时间】:2017-07-09 13:47:04
【问题描述】:
我正在尝试将 JSON 文件导入表中。我正在使用这里提到的解决方案:https://stackoverflow.com/a/33130304/1663462:
create temporary table temp_json (values text) on commit drop;
copy temp_json from 'data.json';
select
values->>'annotations' as annotationstext
from (
select json_array_elements(replace(values,'\','\\')::json) as values
from temp_json
) a;
Json文件内容为:
{"annotations": "<?xml version=\"1.0\"?>"}
我已验证这是一个有效的 JSON 文件。
json 文件包含一个\",我认为它是导致以下错误的原因:
CREATE TABLE
COPY 1
psql:insertJson2.sql:13: ERROR: invalid input syntax for type json
DETAIL: Expected "," or "}", but found "1.0".
CONTEXT: JSON data, line 1: {"annotations": "<?xml version="1.0...
是否有任何额外的字符需要转义?
【问题讨论】:
标签: json postgresql