How to escape Special characters while using export to delimited.
In my product we are using vertica version 12.04 where we are using export to delimited to export csv into s3 bucket. This is a sample data :-
select * from srijan;
id | name
----+------------------------
1 | srijan chakraborty
2 | Mr, srijan chakraborty
3 | X"≫
4 | "lakshman"'
How to get proper valid parsable csv while doing export to delimited with delimiter as , ?
0
Answers
Have you looked at the
EXPORT TO DELIMITED()
command?Check this out :
https://docs.vertica.com/23.4.x/en/sql-reference/statements/export-to-delimited/
What you showed in your question is the output of vsql when you launch it and send its output to the screen.
When I export to delimited (in my case to a Posix directory, but the file would look the same in an S3 bucket), I would to this to get RFC compliant output:
... to get this file:
under my case I get the following file on doing export to delimited EXPORT TO DELIMITED (directory='s3://vertica-s3-export-stg1/bench', delimiter=',', enclosedBy='"', escapeAs='"', addHeader='true', filename='test') AS SELECT * FROM (SELECT * from srijan) AS FinalUser;
file output as following :-
Try this:
Because the table data itself can contain commas, vertical bars, new lines, slashes, and backslashes,
it is advised to use a delimiter that consists of non-printable characters to export data.
In the following example, we will use \001 (CTRL-A) as field separator.
In addition, to avoid confusion between NULLs and EMPTY STRINGS, we can use the string REALNULL to represent NULLs in the output file.