简体   繁体   English

如何为 bigquery 声明常量列表

[英]How to declare a list of constants for bigquery

just playing around with setting parameters in BigQuery.只是在 BigQuery 中设置参数。

I know this works:我知道这有效:

DECLARE X STRING;
SET X = 'APPLE'

SELECT *
FROM DATASET
WHERE name = X

Now I want to set a list of parameters to be used as a reference, like:现在我想设置一个参数列表作为参考,比如:

DECLARE X ???;
SET X = {'APPLE','BANANA','CHERRY'}

SELECT *
FROM DATASET
WHERE name in UNNEST(X)

What should I use in '???'我应该在'???'中使用什么Using string obviously gave an使用字符串显然给出了一个

Query error: Cannot coerce expression查询错误:无法强制表达

error, but I am unsure what category to use.错误,但我不确定要使用哪个类别。 Array doesn't seem to work either?数组似乎也不起作用? :( :(

Thanks for the help.谢谢您的帮助。 CN中国

You want an array of strings.你想要一个字符串数组。 I would write this as:我会这样写:

DECLARE X array<string>;
SET X = array['APPLE', 'BANANA', 'CHERRY'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM