从 Python 工作表创建存储过程¶
You can create a stored procedure from a Python worksheet by using Snowsight.
例如,您可以在 Python 工作表中编写代码,用于从 Snowflake 中的暂存区或数据库对象提取数据、转换数据,并将转换后的数据存储在 Snowflake 中。然后,您可以将该代码部署为存储过程并构建数据管道,而无需离开 Snowflake。
Create a Python stored procedure from your Python worksheet to automate your code. For details on writing Python worksheets, see Writing Snowpark Code in Python Worksheets.
先决条件
您的角色必须对运行 Python 工作表的数据库架构具有 OWNERSHIP 或 CREATE PROCEDURE 权限,才能将其部署为存储过程。
将 Python 工作表部署为存储过程¶
要创建 Python 存储过程来自动执行 Python 工作表中的代码,请执行以下操作:
- Sign in to Snowsight.
- In the navigation menu, select Projects » Worksheets.
- 打开要部署为存储过程的 Python 工作表。
- Select Deploy.
- 输入存储过程的名称。
- (可选)输入有关存储过程的详细信息的注释。
- (Optional) Select Replace if exists to replace an existing stored procedure with the same name.
- For Handler, select the handler function for your stored procedure. For example,
main. - Review the arguments used by your handler function and, if needed, override the SQL data type mapping for a typed argument. For details about how Python types are mapped to SQL types, see SQL-Python Data Type Mappings.
- (Optional) Select Open in Worksheets to open the stored procedure definition in a SQL worksheet.
- Select Deploy to create the stored procedure.
- After the stored procedure is created, you can go to the procedure details or select Done.
您可以从一张 Python 工作表创建多个存储过程。
After you create a stored procedure, you can automate it as part of a task. Refer to Introduction to tasks.