snowflake.snowpark.Session.call¶
- Session.call(sproc_name: str, *args: Any, statement_params: Optional[Dict[str, Any]] = None, log_on_exception: bool = False) Any [source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/session.py#L2900-L2954)¶
Calls a stored procedure by name.
- Parameters:
sproc_name – The name of stored procedure in Snowflake.
args – Arguments should be basic Python types.
statement_params – Dictionary of statement level parameters to be set while executing this action.
log_on_exception – Log warnings if they arise when trying to determine if the stored procedure as a table return type.
Example:
>>> import snowflake.snowpark >>> from snowflake.snowpark.functions import sproc >>> >>> session.add_packages('snowflake-snowpark-python') >>> >>> @sproc(name="my_copy_sp", replace=True) ... def my_copy(session: snowflake.snowpark.Session, from_table: str, to_table: str, count: int) -> str: ... session.table(from_table).limit(count).write.save_as_table(to_table) ... return "SUCCESS" >>> _ = session.sql("create or replace table test_from(test_str varchar) as select randstr(20, random()) from table(generator(rowCount => 100))").collect() >>> _ = session.sql("drop table if exists test_to").collect() >>> session.call("my_copy_sp", "test_from", "test_to", 10) 'SUCCESS' >>> session.table("test_to").count() 10
Example:
>>> from snowflake.snowpark.dataframe import DataFrame >>> >>> @sproc(name="my_table_sp", replace=True) ... def my_table(session: snowflake.snowpark.Session, x: int, y: int, col1: str, col2: str) -> DataFrame: ... return session.sql(f"select {x} as {col1}, {y} as {col2}") >>> session.call("my_table_sp", 1, 2, "a", "b").show() ------------- |"A" |"B" | ------------- |1 |2 | -------------