Snowflake Solutions Expertise and
Community Trusted By

Enter Your Email Address Here To Join Our Snowflake Solutions Community For Free

Snowflake Solutions Community

How can I write data from a Snowpark DataFrame to a Snowflake table?

2.35K viewsSnowpark
0

How can I write data from a Snowpark DataFrame to a Snowflake table?

Daniel Steinhold Asked question September 13, 2023
0

There are a few ways to write data from a Snowpark DataFrame to a Snowflake table.

  • Using the writeTable() method: This method is available in the Snowpark API for each supported programming language. It takes a few parameters, such as the name of the table and the database in which the table resides.
  • Using the save() method: This method is also available in the Snowpark API for each supported programming language. It takes a few parameters, such as the path to the file where the data will be saved.
  • Using the Snowpark SparkSession: If you are using Snowpark with Spark, you can write data from a Snowpark DataFrame to a Snowflake table by using the Snowpark SparkSession. This class provides a number of convenience methods for writing data to Snowflake tables.

Here is an example of how to write data from a Snowpark DataFrame to a Snowflake table using the writeTable() method in Python:

Python

from snowflake.snowpark import Session
from snowflake.snowpark import DataFrame

session = Session.builder().account("myaccount").user("myuser").password("mypassword").build()

df = session.readTable("mytable", "mydatabase")
df.writeTable("mynewtable", "mydatabase")

Use code with caution. Learn morecontent_copy

Here is an example of how to write data from a Snowpark DataFrame to a Snowflake table using the save() method in Python:

Python

from snowflake.snowpark import Session
from snowflake.snowpark import DataFrame

session = Session.builder().account("myaccount").user("myuser").password("mypassword").build()

df = session.readTable("mytable", "mydatabase")
df.save("/tmp/mynewtable")

Use code with caution. Learn morecontent_copy

Here is an example of how to write data from a Snowpark DataFrame to a Snowflake table using the Snowpark SparkSession in Scala:

Scala

import com.snowflake.snowpark._
import com.snowflake.snowpark.spark._

val session = SnowparkSession.builder()
  .account("myaccount")
  .user("myuser")
  .password("mypassword")
  .build()

val df = session.readTable("mytable", "mydatabase")
df.writeTable("mynewtable", "mydatabase")

Use code with caution. 

Once you have written data to a Snowflake table, you can query the table using SQL or use it in other Snowpark DataFrames.

 

Daniel Steinhold Changed status to publish September 13, 2023
You are viewing 1 out of 1 answers, click here to view all answers.

Sign in with google.com

To continue, google.com will share your name, email address, and profile picture with this site.

Harness the Power of Data with ITS Solutions

Innovative Solutions for Comprehensive Data Management

Feedback on Q&A