snowflake.snowpark.Session.sql¶
- Session.sql(query: str, params: Optional[Sequence[Any]] = None) DataFrame[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/session.py#L2007-L2056)¶
Returns a new DataFrame representing the results of a SQL query.
Note
You can use this method to execute a SQL query lazily, which means the SQL is not executed until methods like
DataFrame.collect()orDataFrame.to_pandas()evaluate the DataFrame. For immediate execution, chain the call with the collect method: session.sql(query).collect().- Parameters:
query – The SQL statement to execute.
params – binding parameters. We only support qmark bind variables. For more information, check https://docs.snowflake.cn/en/developer-guide/python-connector/python-connector-example#qmark-or-numeric-binding
Example: