首页 > 解决方案 > postgres COPY 功能是否支持 utf 16 编码文件?

问题描述

我正在尝试使用 postgreSQLCOPY函数将 UTF 16 编码的 csv 插入表中。但是,在运行以下查询时:

COPY temp 
FROM 'C:\folder\some_file.csv' 
WITH (
    DELIMITER E'\t', 
    FORMAT csv, 
    HEADER);

我收到以下错误:

ERROR:  invalid byte sequence for encoding "UTF8": 0xff
CONTEXT:  COPY temp, line 1
SQL state: 22021

当我运行相同的查询,但添加编码设置Encoding 'UTF-16'Encoding 'UTF 16'with 块时,我收到以下错误:

ERROR:  argument to option "encoding" must be a valid encoding name
LINE 13:  ENCODING 'UTF 16' );
          ^
SQL state: 22023
Character: 377

我查看了 postgres 文档以尝试找到正确的编码,但没有找到任何东西。这是因为复制功能确实支持 UTF 16 编码文件吗?我原以为这几乎肯定是可能的!

我在 windows 10 pro 上运行 postgres 12

任何帮助将不胜感激!

标签: postgresqlencodingcharacter-encodingutf-16

解决方案


不,你不能那样做。

UTF-16 is not in the list of supported encodings.
PostgreSQL will never support an encoding that is not an extension of ASCII.
You will have to convert the file to UTF-8.


推荐阅读