简体   繁体   English

雪花:仅满足条件时创建或替换表

[英]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.

相关问题 插入但仅在满足另一个表上的条件时 - Insert but only if a condition on another table is met 仅在满足参数条件的情况下与表联接 - JOIN with table only if parameter condition is met sql仅在满足条件时选择查询 - sql Select query only when a condition is met 雪花创建或替换表作为值无法识别 - Snowflake Create or Replace Table as value Not Recognized 如何在满足条件时从另一个表中获取值的表中创建列,但如果条件失败则分配不同的值 - How to create column in a table which takes values from another table when the condition is met but assigns a different value if condition fails 仅在满足条件时分组 - Group only if condition is met Snowflake merge into 正在添加数据,即使满足条件,即使目标表和源表中的字段已经存在 - Snowflake merge into is adding data even when condition is met and even if fields from target and source tables are already exists 当满足表B中的条件时从表A中选择 - select from table A when condition is met in table B SQL:仅在满足条件时,使用同一个表中的值更新字段 - SQL: update a field with a value from the same table, only if condition is met 仅在满足条件时创建 SSDT 对象(存储过程等) - Create SSDT objects (stored procedures etc.) only if a condition is met
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM