How to unload a table on RedShift to a single CSV file?

后端 未结 5 576
醉话见心
醉话见心 2021-02-02 11:36

I want to migrate a table from Amazon RedShift to MySQL, but using \"unload\" will generate multiple data files which are hard to imported into MySQL directly.

Is there

5条回答
  •  自闭症患者
    2021-02-02 12:21

    It is a bit of a workaround, but you need to make your query a subquery and include a limit. It will then output to one file. E.g.

    select * from (select * from bizdata LIMIT 2147483647);
    

    So basically you are selecting all from a limited set. That is the only way it works. 2147483647 is your max limit, as a limit clause takes an unsigned integer argument.

    So the following will unload to one file:

    unload(' select * from (
    select bizid, data
    from biztable
    limit 2147483647);
     ') to 's3://.......' CREDENTIALS 'aws_access_key_id=<>;aws_secret_access_key=<>' csv ; 
    

提交回复
热议问题