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:
Create the Snowflake stage.
Create or replace stage organizations_stage1;
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 = ‘,’;
Upload our CSV file from the local folder to the Snowflake stage through “PUT” command:
put file:///tmp1/data1/Oragnizations.csv @organizations_stage1;
put file://D: \test1\Organizations.CSV @organizations_stage1;
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;
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) )
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);
Check to view if Snowflake database table is inhabited with data
select * from organizations;
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!
|Snowflake Training||Nov 26 to Dec 11|
|Snowflake Training||Nov 29 to Dec 14|
|Snowflake Training||Dec 03 to Dec 18|
|Snowflake Training||Dec 06 to Dec 21|
Kalla Saikumar is a technology expert and is currently working as a content associate at MindMajix. Write articles on multiple platforms such as ServiceNow, Business Analysis, Performance Testing, Mulesoft, Oracle Exadata, Azure, and other courses. And you can join him on LinkedIn.
Copyright © 2013 - 2022 MindMajix Technologies