团队,我使用的是 redshift 版本 *(8.0.2 )。使用 COPY 命令加载数据时,出现错误:-“字符串包含无效或不受支持的 UTF8 代码点,错误的 UTF8 十六进制序列:bf(错误 3)”。似乎 COPY 试图将 UTF-8 "bf" 加载到 VARCHAR 字段中。根据 Amazon redshift,此错误代码 3 定义如下:
error code3:
The UTF-8 single-byte character is out of range. The starting byte must not be 254, 255
or any character between 128 and 191 (inclusive).
Run Code Online (Sandbox Code Playgroud)
亚马逊建议将此作为解决方案 - 我们需要用有效的 UTF-8 代码序列替换该字符或删除该字符。
你能帮我如何用有效的 UTF-8 代码替换字符吗?
当我在 PG-ADMIN 中检查数据库属性时,它显示编码为 UTF-8。
请指导我如何替换输入分隔文件中的字符。
谢谢...
小智 10
在加载 TPC-DS 数据集进行实验时,我在 RedShift 中遇到了这个问题。
这是我通过 AWS 找到的文档和论坛讨论:https : //forums.aws.amazon.com/ann.jspa? annID =2090
这是您可以用来解决数据转换错误的显式命令:http : //docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html#copy-acceptinvchars
您可以在 COPY 阶段通过声明 ACCEPTINVCHARS 明确替换无效的 UTF-8 字符或一起忽略它们。
尝试这个:
copy table from 's3://my-bucket/my-path
credentials 'aws_iam_role=<your role arn>'
ACCEPTINVCHARS
delimiter '|' region 'us-region-1';
Warnings:
Load into table 'table' completed, 500000 record(s) loaded successfully.
Load into table 'table' completed, 4510 record(s) were loaded with replacements made for ACCEPTINVCHARS. Check 'stl_replacements' system table for details.
0 rows affected
COPY executed successfully
Execution time: 33.51s
Run Code Online (Sandbox Code Playgroud)
听起来您的文件编码可能不是 utf-8。您可以尝试我们有时使用的这种技术
cat myfile.tsv| iconv -c -f ISO-8859-1 -t utf8 > myfile_utf8.tsv
Run Code Online (Sandbox Code Playgroud)