31 January 2019 ยท n-pacha ยท       Add to Favorites   Report

Unloading data from Snowflake tables


Similar to data loading, Snowflake supports bulk export (i.e. unload) of data from a database table into flat, delimited text files. 

First, Set the Context:

USE WAREHOUSE TRAINING_WH;
USE DATABASE SALES_NAVEEN_DB;
USE SCHEMA SALES_DATA;

For the purpose of this tutorial let us create a temporary sales table, from where we can unload the data

CREATE TABLE SALES_NAVEEN_DB.SALES_DATA.SALES AS select * from snowflake_sample_data.TPCDS_SF100TCL.STORE_SALES LIMIT 1000;

Create a named stage:

create stage my_unload_stage;

Unload the table into a file in the named stage:

copy into @my_unload_stage
from (select * from SALES_NAVEEN_DB.SALES_DATA.SALES)
file_format = (type = csv field_optionally_enclosed_by='"');

List the files to make sure the export was successful

list @my_unload_stage;

Finally, download the files to our local system:

get @my_unload_stage file://C:\Users\Naveen\Desktop\unload;

๐Ÿ“™ Course Index
โ—€ Prev: Load Data using SnowSQL
โ–ถ Next:


Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied