Hurry! 20% Off Ends SoonRegister Now

How to Import a CSV in Snowflake

In Snowflake, we can upload CSV(Comma-Separated Values) files from the local machines that are available on macOS, Windows, and Linux operating systems. In this blog, we will discuss the process of importing the CSV files.

Import a CSV in Snowflake

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:

  • Twitter, Canada
  • Amazon, Washington
  • Flipkart, California

Steps

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;

 MindMajix YouTube Channel

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.idO.nameO.locatio
101TwitterCanada
102AmazonWashington
103FlipkartCalifornia

Conclusion

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


▶  Snowflake vs Redshift
▶  Snowflake vs BigQuery
▶  Snowflake vs Databricks
▶  Snowflake vs Azure
▶  Snowflake vs Hadoop
▶  Snowflake Time Travel

If you have any queries, let us know by commenting below.

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Snowflake TrainingDec 24 to Jan 08View Details
Snowflake TrainingDec 28 to Jan 12View Details
Snowflake TrainingDec 31 to Jan 15View Details
Snowflake TrainingJan 04 to Jan 19View Details
Last updated: 07 Apr 2023
About Author

Kalla Saikumar is a technology expert and is currently working as a Marketing Analyst at MindMajix. Write articles on multiple platforms such as Tableau, PowerBi, Business Analysis, SQL Server, MySQL, Oracle, and other courses. And you can join him on LinkedIn and Twitter.

read less
  1. Share:
Snowflake Articles