Snowflake lets us upload the CSV file from our local machines that run on Linux, macOS, or Windows. In the following example, the file we import is known as “Organizations.” It will have three columns(O.id, O.location, and O.name), is located in the ‘test1’ folder of the local machine, and contains the below structure:
Step1:
Create the Snowflake stage.
Create or replace stage organizations_stage1;
Step2:
Create the file format through “FILE FORMAT” command for explaining the format of the file we import:
create or replace file format organizations_format type = ‘CSV’ field delimiter = ‘,’;
Step3:
Upload our CSV file from the local folder to the Snowflake stage through “PUT” command:
Linux/Mac:
put file:///tmp1/data1/Oragnizations.csv @organizations_stage1;
Windows:
put file://D: \test1\Organizations.CSV @organizations_stage1;
Step4:
Check to view if Snowflake stage is inhabited with data from file.
Select
b.$1,
b.$2,
b.$3
from @_stage1 (file_format => organizations_format1) c;
Step5:
We have to create the table in the Snowflake database that contains a similar structure to the CSV file we have to import before running “COPY INTO” command.
Create or replace table organizations (
O.Id integer,
O.name varchar(100),
O.location varchar(100)
)
Step6:
Load the data from the Snowflake stage into the Snowflake database table through the “COPY INTO” command
copy into test.organizations from @organizations_stage1;
copy into test.organizations from (select c.$1, c.$2, from @organizations_stage1 (file_format1 => organizations_format1) c);
Step7:
Check to view if Snowflake database table is inhabited with data
select * from organizations;
O.id | O.name | O.locatio |
101 | Canada | |
102 | Amazon | Washington |
103 | Flipkart | California |
This blog includes all the steps required for importing the CSV(Comma Separated Values) files into the Snowflake. It also tells you how to get the output in the required format. I hope this is sufficient for working with the CSV files in Snowflake.
Snowflake Related Articles
If you have any queries, let us know by commenting below.
Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!
Name | Dates | |
---|---|---|
Snowflake Training | Aug 05 to Aug 20 | |
Snowflake Training | Aug 08 to Aug 23 | |
Snowflake Training | Aug 12 to Aug 27 | |
Snowflake Training | Aug 15 to Aug 30 |
1 /10
Copyright © 2013 - 2023 MindMajix Technologies