Are you using Snowflake as your warehousing solution? Are you looking for ways to modify and grow your tables? If yes? then you’ve landed at the right page! This article teaches you how to efficiently use the Snowflake Insert command. It provides you with a step-by-step guide to help you use the Insert command and insert multiple data records to your existing and newly created Snowflake tables.

Introduction to Snowflake

snowflake logo

Snowflake is a fully managed cloud-hosted data warehouse available as Software-as-a-Service (SaaS). Snowflake provides an agile and easy to use data warehouse service and possesses many similarities to a traditional data warehouses with additional capabilities. Snowflake uses a new SQL database engine and AWS Cloud services for storage (S3) and computation (EMR). It performances exceptionally well even with enormous volumes of data.

Key features of Snowflake:

  • Low Maintenance: All the maintenance, management, and performance tuning are handled by Snowflake, thereby providing a fully managed service.
  • Managed Cloud: Snowflake runs entirely on public cloud instances, and uses virtual compute instances and storage services.
  • Highly Secure: Snowflake provides top-notch security for data at rest and on-flight to ensure user information is always safe.
  • No Hardware: There is no requirement to set up, configure, install, or manage the hardware.
  • Speed: Snowflake uses a concept of MPP (Massive Parallel Processing) to process queries on a virtual warehouse. Each warehouse has its cluster with exceptional scaling capability.
  • Separate Storage and Compute Layer: Snowflake uses different storage and computes layers that can scale up or down without affecting each other.
Hevo Data, an alternative you can depend on to load data efficiently

Hevo Data, a No-code Data Pipeline helps to transfer data from 150+ sources to Snowflake. Hevo is fully-managed and completely automates the process of not only exporting data from your desired source but also enriching the data and transforming it into an analysis-ready form without having to write a single line of code. Its fault-tolerant architecture ensures that the data is handled in a secure, consistent manner with zero data loss.

It provides a consistent & reliable solution to manage data in real-time and always have analysis-ready data in your desired destination. It allows you to focus on key business needs and perform insightful analysis. 

Check out some amazing features of Hevo (Official Snowflake ETL Partner):

  • Completely Managed Platform: Hevo is fully managed. You need not invest time and effort to maintain or monitor the infrastructure involved in executing codes.
  • Live Monitoring: Hevo allows you to monitor the data flow and check where your data is at a particular point in time.
  • Data Transformation: It provides a simple interface to perfect, modify, and enrich the data you want to export. 
  • Secure: Hevo has a fault-tolerant architecture that ensures that the data is handled in a secure, consistent manner with zero data loss.
  • Schema Management: Hevo takes away the tedious task of Schema management & automatically detects the Schema of incoming data and maps it to the destination Schema.
  • Minimal Learning: Hevo with its simple and interactive UI, is extremely simple for new customers to work on and perform operations.

Get started with Hevo (Official Snowflake ETL Partner) today! 

SIGN UP HERE FOR A 14-DAY FREE TRIAL

Prerequisites

  • Working knowledge of Snowflake.
  • A general idea of the command-line.
  • Snowflake account and database.

Using the Snowflake Insert command

The Snowflake Insert command is an excellent way to add data into your tables stored in Snowflake. This command is not only used to insert data into an existing table but also to insert data into a newly created table. The data can be a set of manually typed data records or can even be copied from a particular source.

In addition to the Insert command, Snowflake offers various other features/commands to help simplify your data warehousing experience. Some of these are comprehensive shortcuts, scripting features and high-security shortcuts.

Learn more about SnowSQL

You can use the Snowflake Insert command using the following syntax:

INSERT [ OVERWRITE ] INTO <target_table> [ ( <target_col_name> [ , ... ] ) ]
                                         { { VALUES ( { <value> | DEFAULT | NULL } [ , ... ] ) [ , ( ... ) ] } | <query> }

Fill the following parameters carefully to use the Insert command:

  • <target_table>: Enter the name of the table you want to use to insert records.
  • <query> or VALUES: This field specifies the data that you want to insert into the table.

You can perform various operations using the Snowflake Insert command:

1. Inserting a single record using Snowflake Insert command

You can use the Insert command to add a single row of data as follows:

insert into mytable (col1, col3)
  select to_date('2013-05-08T23:39:20.123'), to_timestamp('2013-05-08T23:39:20.123');

This command inserts data into column1 and column3 of the table “mytable” stored in your Snowflake data warehouse. The column2 remains unaffected as it is not included in the query being used to insert data.

You can now use a select statement to fetch data from the table and see how the table has been modified. You can use the following command:

select * from mytable;

The Select command will retrieve the data stored in the table and generate the following output:

snowflake insert

2. Inserting multiple records using Snowflake Insert command

You can use the Insert command to add multiple records of data to your desired table in Snowflake. First, use the select statement to retrieve the existing data from your table using the following command:

select * from employee;

The Select command will retrieve the data stored in the table and generate the following output:

inserting multiple records into table

The employee table currently stores two records. You can now use the Snowflake Insert command and add multiple data records to your table. Use the following command to insert two new employee records:

insert into employee
  values
  ('Lysandra','Reeves','1-212-759-3751','New York',10018),
  ('Michael','Arnett','1-650-230-8467','San Francisco',94116);

Use the Select statement to retrieve data from the employee table to check how the table has been modified:

select * from employee;

The Select command will retrieve the data stored in the table and generate the following output:

Select command output.

The employee table has been modified and it now, contains two new records. This is how you can use the Snowflake Insert command to insert multiple data records in your desired table easily.

3. Inserting nested data using Snowflake Insert command

The Insert command lets you insert the data fetched by querying a particular table and then inserting the resultant data into your desired Snowflake table.

For example, if you’re working with two tables, namely contractor and employee and you want to insert data from contractor table into the employee table, you can do this easily using the Insert command.

First, use the select statement to retrieve the existing data from your tables using the following commands:

select * from employee;

The Select command will retrieve the entire data stored in the employee table as follows:

Inserting nested data,
select * from contractor;

The Select command will retrieve the entire data stored in the contractor table as follows:

Select command output.

You can now use the Insert command and make use of a nested SQL query to insert data into the employee table by fetching it from the contractor table as follows:

insert into employees(first_name, last_name, workphone, city,postal_code)
  select
    contractor_first,contractor_last,worknum,null,zip_code
  from contractors
  where contains(worknum,'650');

Use the Select statement to retrieve data from the employee table to check how the table has been modified:

select * from employees;
Table modified.

This is how you can use the Snowflake Insert command to add new data records into your desired tables.

Conclusion

This article teaches you how to successfully use the Insert command to add data to your desired Snowflake table. It provides in-depth knowledge about the concepts behind every step to help you understand and implement them efficiently. These methods, however, can be challenging, especially for a beginner & this is where Hevo saves the day.

Hevo Data, a No-code Data Pipeline helps to transfer data from 150+ sources to Snowflake without having to write the code repeatedly. Hevo with its strong integration allows you to not only export & load data but also transform & enrich your data to make it analysis-ready. Try a 14-day free trial and experience the feature-rich Hevo suite firsthand. Also, check out our unbeatable pricing to choose the best plan for your organization.

Frequently Asked Questions

1. Can I insert data into a view?

No. Snowflake doesn’t allow you to insert data into a view directly. Views are virtual tables whose content is defined based on other existing tables, so you need to insert data into those source tables.

2. How can I handle duplicate rows during an insert?

Use of MERGE or handling the programmatic operations before inserting avoids duplicate insertion.

3. What is the maximum size of an INSERT statement in Snowflake?

Although specific limits on the number of rows that can exist in an INSERT statement do not occur, very large inserts will impact performance. Better to use bulk inserts for a significant load of data.

Veeresh Biradar
Senior Customer Experience Engineer

Veeresh is a skilled professional specializing in JDBC, REST API, Linux, and Shell Scripting. With a knack for resolving complex issues and implementing Python transformations, he plays a crucial role in enhancing Hevo's data integration solutions.