Export table as RFC 4180 CSV
Is there a way to export a Vertica table as an RFC 4180 CSV, with just strings that contain embedded commas, quotes, line breaks, etc. enclosed by quotes, and embedded quotes escaped as double quotes?
I see this article which shows how to export with simple comma delimited values and use a unix command to enquote everything, but can this handle more general strings and not enquote columns that are not VARCHAR?
https://www.vertica.com/blog/create-a-csv-file-with-fields-enclosed-by-quotes/
0
Answers
I think it's a matter of SQL generating SQL, taking advantage of Vertica's string over-standard function library.
Creating an exemplary test table:
Now generate the SQL you will finally run. Put the below into a SQL file called gen_exp.sql.
Testing:
running:
If you need a title line in the output, shout. If you need numerics to not be in quotes, shout, too. Both of those can be generated with the help of the
columns
system table, too.Couldn't edit it and had some time. Might come in handy for myself in the future ....
Here goes the whole SQL generating SQL script. I check for int, numeric or float as basic data types for refraining from quoting the literals, and rely, for now getting away with it, to receive the rows in a UNION SELECT in the order I placed the various SELECTs into the overall UNION SELECT statement - so that the generation of the title line happens before the generation of the row lines ...