Skip to content

Instantly share code, notes, and snippets.

@laughingman7743
Created September 15, 2014 06:59
Show Gist options
  • Save laughingman7743/ed5e708979f9ea6e9326 to your computer and use it in GitHub Desktop.
Save laughingman7743/ed5e708979f9ea6e9326 to your computer and use it in GitHub Desktop.
select
column1,
column2,
column3,
column4,
column5
from (
select
'"column1"' column1,
'"column2"' column2,
'"column3"' column3,
'"column4"' column4,
'"column5"' column5,
0 as sort_order
union all
select
'"' || coalesce(cast(column1 as text), '') || '"',
'"' || coalesce(cast(column2 as text), '') || '"',
'"' || coalesce(cast(column3 as text), '') || '"',
'"' || coalesce(cast(column4 as text), '') || '"',
'"' || coalesce(cast(column5 as text), '') || '"',
1
from my_table
)
order by sort_order;
unload ('
select
column1,
column2,
column3,
column4,
column5
from (
select
\'"column1"\' column1,
\'"column2"\' column2,
\'"column3"\' column3,
\'"column4"\' column4,
\'"column5"\' column5,
0 as sort_order
union all
select
\'"\' || coalesce(cast(column1 as text), \'\') || \'"\',
\'"\' || coalesce(cast(column2 as text), \'\') || \'"\',
\'"\' || coalesce(cast(column3 as text), \'\') || \'"\',
\'"\' || coalesce(cast(column4 as text), \'\') || \'"\',
\'"\' || coalesce(cast(column5 as text), \'\') || \'"\',
1
from my_table
)
order by sort_order;
')
TO 's3://object_path_prefix'
credentials 'aws_access_credentials'
gzip delimiter AS ',' escape allowoverwrite manifest parallel off;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment