简体   繁体   English

从S3复制到Redshift无法识别换行符

[英]COPY from S3 to Redshift not recognizing newline

I am trying to run a COPY command from an S3 bucket to a Redshift PostgreSQL table, and I am getting the following error (in stl_load_errors): 我正在尝试将COPY命令从S3存储桶运行到Redshift PostgreSQL表,并且出现以下错误(在stl_load_errors中):

err_code: 1207 

err_reason: Invalid digit, Value '2', Pos 3, Type: Short 

raw_field_value: 
2
2/28/15

The file has 2 lines: 该文件有2行:

2/28/15,Phone,Android,0,1,3,2,2 28分之2/ 15电话,机器人,0,1,3,2,2

2/28/15,Phone,Android,0,4,1,2,2 28分之2/ 15电话,机器人,0,4,1,2,2

The CREATE TABLE code is: CREATE TABLE代码是:

create table aggregate_table( date date, variable varchar(15),source varchar(15), prepaid smallint, direction smallint, total smallint, carrier smallint, carrier_group smallint)

It seems like the newline is not being recognized, and is trying to read the end of the first line and the beginning of the second line as one value. 似乎无法识别换行符,并且正在尝试将第一行的末尾和第二行的开始作为一个值读取。 I have tried using delimiter ',' and escape , but nothing seems to work. 我尝试使用delimiter ','escape ,但是似乎没有任何效果。

Thank you for your help! 谢谢您的帮助!

Edit: Here's the COPY command (i've also tried it with escape at the end as well) 编辑:这是COPY命令(我也在结尾处也尝试了escape

COPY aggregate_table FROM 's3://path_to_file.csv'  CREDENTIALS 'aws_access_key_id=XXXX;aws_secret_access_key=XXXXX'  CSV delimiter ','  DATEFORMAT AS 'MM/DD/YY'; 

You need to add DATEFORMAT AS 'MM/DD/YY' to your COPY command. 您需要将DATEFORMAT AS 'MM/DD/YY'到COPY命令中。 Otherwise redshift can not parse date in first column correctly, as it expects YYYY-MM-DD . 否则,redshift无法正确解析第一列中的日期,因为它需要YYYY-MM-DD

See http://docs.aws.amazon.com/redshift/latest/dg/r_DATEFORMAT_and_TIMEFORMAT_strings.html for more details. 有关更多详细信息,请参见http://docs.aws.amazon.com/redshift/latest/dg/r_DATEFORMAT_and_TIMEFORMAT_strings.html

@quarterdome thanks for working through this with me! @quarterdome感谢您与我一起工作! After you pointed out that it worked, I tried from the beginning to end again. 在您指出它可行之后,我从头到尾再次尝试。 It turns out that when I saved the file without a .csv extension, it worked! 原来,当我保存不带.csv扩展名的文件时,它起作用了! -

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM