从与FROM
创建的数组字符串,我想包括一个IF
条件,但bigquery告诉我,这是不可能的。我有以下错误Syntax error: Expected ")" but got keyword FROM
每当我试图做这样的事情:
SELECT
IF(TRUE, STRING_AGG(x, ' | ')
FROM UNNEST([
IF(FALSE, 'new_customer', NULL),
IF(TRUE, 'new_customer_vertical', NULL),
IF(TRUE, 'new_customer_expedition', NULL),
IF(FALSE, 'new_customer_pandapro', NULL)
]) AS x, NULL)
如果移除IF
条件,则传递
SELECT
STRING_AGG(x, ' | ')
FROM UNNEST([
IF(FALSE, 'new_customer', NULL),
IF(TRUE, 'new_customer_vertical', NULL),
IF(TRUE, 'new_customer_expedition', NULL),
IF(FALSE, 'new_customer_pandapro', NULL)
]) AS x
不确定下面是你想做的,但你看起来想要一个标量子查询在IF()函数。
SELECT IF(TRUE, -- some condition
(SELECT STRING_AGG(x, ' | ')
FROM UNNEST([
IF(FALSE, 'new_customer', NULL),
IF(TRUE, 'new_customer_vertical', NULL),
IF(TRUE, 'new_customer_expedition', NULL),
IF(FALSE, 'new_customer_pandapro', NULL)
]) AS x
), -- IF true
NULL) -- IF false