[英]snowflake: create or replace table when only a condition is met
I have a requirement to create or replace a table only if certain variable value is 1仅当某些变量值为 1 时,我才需要创建或替换表
SET variable = (select statement) -- $variable will be 1 or 0 depending on value returned from select statment
create or replace table2 as select * from table1 (only if $variable =1)
Is there any way to do it?有什么办法吗? If the variable value is 0, the create statement should be skipped
如果变量值为0,则应跳过create语句
Using Snowflake Scripting block:使用雪花脚本块:
-- CREATE TABLE table1 AS SELECT 1 AS col;
SET variable = (SELECT 1);
BEGIN
IF ($variable = 1) THEN
create or replace table table2 as select * from table1;
END IF;
END;
Variable could be defined also at Snowflake Scripting block level:变量也可以在 Snowflake Scripting 块级别定义:
DECLARE
variable INTEGER := (SELECT 1);
BEGIN
IF (:variable = 1) THEN
create or replace table table2 as select * from table1;
END IF;
END;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.