取消语句
取消语句的推荐方法是,使用运行查询的应用程序的界面(例如 Snowflake Web 界面中的 Worksheet),或者使用由 Snowflake ODBC 或 JDBC 驱动程序提供的取消 API。但是,在某些情况下,必须使用 SQL 取消查询。
Snowflake 提供以下函数,以支持使用 SQL 取消正在运行的/活跃的语句:
示例
The following Java sample code uses SYSTEM$CANCEL_ALL_QUERIES and other Snowflake functions to cancel a running statement in the current session after 5 seconds:
- The sample code first issues a SQL command for CURRENT_SESSION to obtain the session identifier.
- It then creates a task to be executed 5 seconds later. This task uses the session identifier as a parameter to SYSTEM$CANCEL_ALL_QUERIES.
- Then a long running statement is executed using the GENERATOR table function to generate rows for 120 seconds.