EXECUTE NOTEBOOK
statementsupportedContainer services & dev toolingExecutes the notebook outside the Notebook Editor. For example, you can run EXECUTE NOTEBOOK by itself from a worksheet, nest it within another Snowflake executable such as a stored procedure or task, or use it in a third-party orchestrator. The command runs the latest code from all cells in the notebook. Results are accessible from the Notebook Editor. Note EXECUTE NOTEBOOK also requires the QUERY_WAREHOUSE parameter to be set, otherwise an error occurs. To set the QUERY_WAREHOUSE parameter, use the ALTER NOTEBOOK command.
Syntax
EXECUTE NOTEBOOK <name>([ <parameter_string> [ , ... ] ]);
Parameters
| Name | Required | Description |
|---|---|---|
name | required | Specifies the identifier (i.e. name) for the notebook; must be unique for the schema in which the notebook is created. Must be fully qualified if the notebook is not stored in the current database.schema you are operating in. In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, “My object”). Identifiers enclosed in double quotes are also case-sensitive. For more information, see Identifier requirements. |
parameter_string | optional | Optionally pass in arguments to a notebook. In a Python cell in the notebook, you can access these arguments by using the sys.argv variable. Only strings are supported; other data types (such as integers or booleans) are interpreted as NULL. |
Usage notes
- When you run a notebook using the EXECUTE NOTEBOOK command:
- Python cells are executed on the compute pool defined by the RUNTIME parameter.
- SQL and Snowpark queries are executed using the virtual warehouse specified in the WAREHOUSE parameter.
- Snowflake doesn’t support embedding the EXECUTE NOTEBOOK command in a task that is configured to EXECUTE AS USER. You will not see an error message when creating such a task, but when the task is executed, it will fail.
- When you execute a notebook that uses a compute pool, the Python code runs on the compute pool. However, you might see activity in Query History showing that a warehouse was used to run the EXECUTE NOTEBOOK command. This is expected behavior. The warehouse is used briefly to initialize the notebook execution environment, but it does not consume any warehouse credits. All code execution is handled by the compute pool.
Access control requirements
A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes OWNERSHIP | Notebook | OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.
Example
The following example triggers the default version of the specified notebook without passing in any arguments: