我嘗試從包含json行的表中加載一些數據。
有一個字段可以包含特殊字符\ t和\ r,並且我想將它們保留在新表中。postgresql json列錯誤字符的值必須轉義
這裏是我的文件:
{"text_sample": "this is a\tsimple test", "number_sample": 4}
這裏是我做的:
Drop table if exists temp_json;
Drop table if exists test;
create temporary table temp_json (values text);
copy temp_json from '/path/to/file';
create table test as (select
(values->>'text_sample') as text_sample,
(values->>'number_sample') as number_sample
from (
select replace(values,'\','\\')::json as values
from temp_json
) a);
我不斷收到此錯誤:
ERROR: invalid input syntax for type json
DETAIL: Character with value 0x09 must be escaped.
CONTEXT: JSON data, line 1: ...g] Objection to PDDRP Mediation (was Re: Call for...
如何,我需要逃避這些字符?
非常感謝
發佈包含違規的樣本數據行。 –
我更新了所有需要的細節 –
'copy temp_json from program'sed -e''s/\\/\\\\/g''/ path/to/file';'? – Abelisto