I am trying to unload a CSV file from Snowflake where only non-null values are quoted and enclosed in double quotes.
Here is my table
|BizName |BizOwner |
|----------+-------------------|
| "NiceOne" LLC | Robert |
| GoodRX | |
| MaxLift | Brian |
| P,N and B | Jane |
+----------+--------------------
Here is my desired output -
"""NiceOne"" LLC","Robert","GoodRX",,"Maxift","Brian","P,N and B","Jane"
Here are 2 examples of formats I have tried
I have tried using the below format, which wraps null values in quotes
create or replace file format formatA
COMPRESSION = GZIP
RECORD_DELIMITER = ','
SKIP_HEADER = 1
FIELD_DELIMITER = NONE
FILE_EXTENSION = 'csv'
ESCAPE = NONE
ESCAPE_UNENCLOSED_FIELD = NONE
FIELD_OPTIONALLY_ENCLOSED_BY = '"'
NULL_IF = ( '','NULL' , 'null' , '""' )
EMPTY_FIELD_AS_NULL = TRUE
copy into @mytablestage from mytable FILE_FORMAT = ( FORMAT_NAME = 'formatA' ) ON_ERROR = CONTINUE
I have tried the below format, which wraps nothing in quotes
create or replace file format formatB
COMPRESSION = GZIP
RECORD_DELIMITER = ','
SKIP_HEADER = 1
FIELD_DELIMITER = NONE
FILE_EXTENSION = 'csv'
ESCAPE = NONE
ESCAPE_UNENCLOSED_FIELD = NONE
NULL_IF = ( '','NULL' , 'null' , '""' )
EMPTY_FIELD_AS_NULL = TRUE
copy into @mytablestage from mytable FILE_FORMAT = ( FORMAT_NAME = 'formatB' ) ON_ERROR = CONTINUE