ERROR: Write preference and partitioning field are not supported with DDL/DML statements

ERROR: Write preference and partitioning field are not supported with DDL/DML statements

我正在尝试使用此查询在 BigQuery 中安排 table

DECLARE isEmpty DEFAULT (SELECT COUNT(keyword) = 0 from dataset.check_table);

DECLARE isFilled DEFAULT (SELECT COUNT(keyword) > 0 from dataset.check_table);

IF isEmpty
  THEN SELECT * FROM dataset.table_a;

ELSEIF isFilled
  THEN SELECT * FROM dataset.table_b;

END IF;

原来是排程不行给了我

ERROR: Write preference and partitioning field are not supported with DDL/DML statements

然后,我尝试使用一种变通方法将该查询作为视图使用:

CREATE OR REPLACE VIEW dataset.v_table AS

DECLARE isEmpty DEFAULT (SELECT COUNT(keyword) = 0 from dataset.check_table);

DECLARE isFilled DEFAULT (SELECT COUNT(keyword) > 0 from dataset.check_table);

IF isEmpty
  THEN SELECT * FROM dataset.table_a;

ELSEIF isFilled
  THEN SELECT * FROM dataset.table_b;

END IF;

但我做不到,因为它给了我另一个错误:

Syntax error: Expected "(" or keyword SELECT or keyword WITH but got keyword DECLARE at [3:1]

这里有人知道我可以安排时间吗?

提前致谢

尝试这样做:

SELECT
  *
FROM
  UNNEST( 
    (SELECT
      (
        CASE (SELECT COUNT(keyword)  from dataset.check_table) = 0
        WHEN TRUE 
        THEN ( 
             SELECT ARRAY( 
                           SELECT AS STRUCT *
                           FROM dataset.table_a)
        )
        ELSE (SELECT ARRAY( 
                           SELECT AS STRUCT *
                           FROM dataset.table_b)
        )
        END
      )
   )
)