snowflake.snowpark.DataFrameWriter.save_as_table¶
- DataFrameWriter.save_as_table(table_name: str | Iterable[str], *, mode: str | None = None, column_order: str = 'index', create_temp_table: bool = False, table_type: Literal['', 'temp', 'temporary', 'transient'] = '', statement_params: Dict[str, str] | None = None, block: bool = True) None [source]¶
- DataFrameWriter.save_as_table(table_name: str | Iterable[str], *, mode: str | None = None, column_order: str = 'index', create_temp_table: bool = False, table_type: Literal['', 'temp', 'temporary', 'transient'] = '', statement_params: Dict[str, str] | None = None, block: bool = False) AsyncJob
Writes the data to the specified table in a Snowflake database.
- Parameters:
table_name – A string or list of strings that specify the table name or fully-qualified object identifier (database name, schema name, and table name).
mode –
One of the following values. When it’s
None
or not provided, the save mode set bymode()
is used.”append”: Append data of this DataFrame to existing data.
”overwrite”: Overwrite existing data.
”errorifexists”: Throw an exception if data already exists.
”ignore”: Ignore this operation if data already exists.
column_order –
When
mode
is “append”, data will be inserted into the target table by matching column sequence or column name. Default is “index”. Whenmode
is not “append”, thecolumn_order
makes no difference.”index”: Data will be inserted into the target table by column sequence. “name”: Data will be inserted into the target table by matching column names. If the target table has more columns than the source DataFrame, use this one.
create_temp_table – (Deprecated) The to-be-created table will be temporary if this is set to
True
.table_type – The table type of table to be created. The supported values are:
temp
,temporary
, andtransient
. An empty string means to create a permanent table. Learn more about table types here.statement_params – Dictionary of statement level parameters to be set while executing this action.
block – (Experimental) A bool value indicating whether this function will wait until the result is available. When it is
False
, this function executes the underlying queries of the dataframe asynchronously and returns anAsyncJob
.
Examples:
>>> df = session.create_dataframe([[1,2],[3,4]], schema=["a", "b"]) >>> df.write.mode("overwrite").save_as_table("my_table", table_type="temporary") >>> session.table("my_table").collect() [Row(A=1, B=2), Row(A=3, B=4)] >>> df.write.save_as_table("my_table", mode="append", table_type="temporary") >>> session.table("my_table").collect() [Row(A=1, B=2), Row(A=3, B=4), Row(A=1, B=2), Row(A=3, B=4)] >>> df.write.mode("overwrite").save_as_table("my_transient_table", table_type="transient") >>> session.table("my_transient_table").collect() [Row(A=1, B=2), Row(A=3, B=4)]