错误:加载到表中-COPY命令中的数据无效

时间:2019-04-16 10:09:01

标签: amazon-web-services amazon-redshift

我正在使用COPY命令将数据从CSV文件导入Amazon Redshift并出现错误:

COPY table1 FROM 's3://cucket1/table1.csv' 
credentials 'aws_access_key_id=aaaa;aws_secret_access_key=aaaa' 
IGNOREHEADER 1  
csv 
NULL AS '\N' 
timeformat 'auto';

错误:装入表'table1'失败。查看“ stl_load_errors”系统表以了解详细信息。

我的csv文件如下:

"id","name","created_at","updated_at"
"1","2","NULL","NULL"
"2","1","NULL","NULL"
"6","1","NULL","NULL"
"87","1","NULL","NULL"

当我从csv文件中删除NULL值时,COPY命令运行正常。 如何在redshift COPY命令中处理NULL值?enter code here

1 个答案:

答案 0 :(得分:2)

看起来您的NULL的格式为"NULL"。这应该起作用:

COPY table1 FROM 's3://cucket1/table1.csv' 
credentials 'aws_access_key_id=aaaa;aws_secret_access_key=aaaa' 
IGNOREHEADER 1  
csv 
NULL AS 'NULL' 
timeformat 'auto';

也可以查看stl_load_errors可以使您更好地了解问题所在。

您尝试过select * from stl_load_errors order by starttime desc limit 100;吗?该查询应为您提供有关无法加载的数据的所有详细信息。我怀疑您的情况是"NULL"未被解析为TIMESTAMP类型。