sqlamazon-web-servicesamazon-s3snowflake-cloud-data-platformsnowflake-task

Snowflake to S3 with Header


Does anyone know of a way to export your data from Snowflake to an S3 file with a header?

For example, I have this table:

Table Example:
+----+-------+
| id | group |
+----+-------+
|  1 | bob   |
|  2 | bob   |
|  3 | bob   |
|  4 | tim   |
|  5 | tim   |
|  6 | carl  |
+----+-------+

I want to export this data to a file that looks like this:

Ex.
  id group 
  1  bob   
  2  bob   
  3  bob   
  4  tim   
  5  tim   
  6  carl  

... but I don't see an option in the Snowflake documentation to do so.

I tried a simple UNION ALL with the names of the columns unioned to the data, but that places my header record randomly in the file.

Ex. 
  1  bob   
  2  bob   
  3  bob   
  4  tim 
  id group   
  5  tim   
  6  carl 

Any and all help would be appreciated!


Solution

  • You can use the copy option HEADER = TRUE | FALSE in your Copy_into Location statement.

    Reference: https://docs.snowflake.com/en/sql-reference/sql/copy-into-location.html#optional-parameters