简体   繁体   English

来自AWS Redshift的“ UNLOAD”数据表,并使它们可读取为CSV

[英]“UNLOAD” data tables from AWS Redshift and make them readable as CSV

I am currently trying to move several data tables in my current AWS instance's redshift database to a new database in a different AWS instance (for background my company has acquired a new one and we need to consolidate to on instance of AWS). 我目前正在尝试将当前AWS实例的redshift数据库中的几个数据表移至另一个AWS实例中的新数据库(出于背景原因,我的公司已收购了一个新数据库,我们需要整合到AWS实例上)。

I am using the UNLOAD command below on a table and I plan on making that table a csv then uploading that file to the destination AWS' S3 and using the COPY command to finish moving the table. 我正在下面的表上使用UNLOAD命令,并计划将该表制作为csv,然后将该文件上传到目标AWS的S3并使用COPY命令完成表的移动。

unload ('select * from table1')
to 's3://destination_folder' 
CREDENTIALS  'aws_access_key_id=XXXXXXXXXXXXX;aws_secret_access_key=XXXXXXXXX'
ADDQUOTES
DELIMITER AS ','
PARALLEL OFF;

My issue is that when I change the file type to .csv and open the file I get inconsistencies with the data. 我的问题是,当我将文件类型更改为.csv并打开文件时,我与数据不一致。 there are areas where many rows are skipped and on some rows when the expected columns end I get additional columns with the value "f" for unknown reasons. 在某些区域中,跳过了许多行,而在预期的列结束时,在某些行上,由于未知原因,我得到了附加列,其值为“ f”。 Any help on how I could achieve this transfer would be greatly appreciated. 对于我如何实现此转移的任何帮助,将不胜感激。

EDIT 1: It looks like fields with quotes are having the quotes removed. 编辑1:看起来带引号的字段正在删除引号。 Additionally fields with commas are having the commas separated away. 此外,带有逗号的字段会将逗号分隔开。 I've identified some fields with quotes and commas and they are throwing everything off. 我已经确定了一些带有引号和逗号的字段,它们使所有内容丢掉了。 Would the addquotes clause I have apply to the entire field regardless of whether there are quotes and commas within the field? 无论字段中是否包含引号和逗号,我已将addquotes子句应用于整个字段吗?

Default document will have extension as txt and with quotes. 默认文档的扩展名为txt,并带有引号。 Try to open it with Excel and then save as csv file. 尝试使用Excel打开它,然后另存为csv文件。 refer https://help.xero.com/Q_ConvertTXT 请参阅https://help.xero.com/Q_ConvertTXT

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

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