Search code examples
csvexport-to-csvsnowflake-cloud-data-platform

Is it possible to include column names in the csv with a copy into statement in Snowflake?


For example:

COPY INTO @my_stage/my_test.csv 
FROM (select * from my_table) 
FILE_FORMAT = (TYPE = CSV) 
OVERWRITE=TRUE SINGLE=TRUE 

will result in a csv but does not include column headers. If it is not possible with a copy into statement, is there perhaps any non-obvious technique that might accomplish this?

Thanks in advance.


Solution

  • We've seen this request before, and it's on our roadmap. If it's high priority for you, please contact Snowflake support.

    If you're looking for a workaround, it's hard to come up with a truly generic one.

    • One option is to add a single row with explicit column names, but you'd need to know them in advance and it might not be efficient if not all your fields are strings.
    • Another is to convert all records using OBJECT_CONSTRUCT(*) and export as JSON, then you will have column names, but it will be of course only useful if you can ingest JSON.

    But I hope Snowflake will add this functionality in the not-so-far future.