将大型 JSON 文件复制到 Postgres 时出现 \u0000 的 Unicode 错误

alx*_*lvt 3 json regex postgresql-9.4 unicode

我在 Ubuntu 14.04 上使用 Postgres 9.4。

我有一个 30GB JSON 文件,我正在尝试将其复制到 Postgres 中。

但我不断收到以下错误:

COPY <table>(comment_jsonb) FROM '<json file>' WITH (format csv, quote e'\x01', delimiter e'\x02', escape e'\x01');
ERROR:  unsupported Unicode escape sequence
DETAIL:  \u0000 cannot be converted to text.
Run Code Online (Sandbox Code Playgroud)

我尝试搜索有问题的 Unicode 字符串来删除它,但因为它是 \u0000,即 NULL,所以我似乎无法使用正则表达式。当我将其打印到控制台时,我不知道 NULL 在哪里,因为(至少我的猜测是)它似乎什么也没有打印(尽管我不知道它实际上在做什么)。

有没有办法跳过这些错误?

或者,如何替换 JSON 文件中该 Unicode 的任何实例?

小智 5

在(也许)类似的情况下,我在需要处理为 JSON 的字符串中遇到了 \u0000 。以下替换对我有用:

regexp_replace(stringWithNull, '\\u0000', '', 'g')
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。