如何在BigQuery中创建一个全为1的数组?

huangapple go评论46阅读模式
英文:

How can one create an array of ones in BigQuery?

问题

在Google BigQuery中是否有一种方法可以创建指定长度的元素为1(或其他任何值)的数组?例如,像Python中的[1]*7,生成列表[1,1,1,1,1,1,1]

GENERATE_ARRAY(start, end, step) 函数不能用于此目的。

我有一个频率表的数据,想要展开它。

英文:

Is there a way to create an array of ones (or anything else) of a given length in Google BigQuery? E.g. like [1]*7 in python, producing the list [1,1,1,1,1,1,1].

The GENERATE_ARRAY(start, end, step) function cannot be used for this.

I have data given to me as a frequency table and would like to expand out.

答案1

得分: 1

以下是翻译好的内容:

-- 即 [1]*7
SELECT ARRAY(SELECT 1 FROM UNNEST(GENERATE_ARRAY(1, 7))) ones;
英文:

You can consider below

-- i.e. [1]*7
SELECT ARRAY(SELECT 1 FROM UNNEST(GENERATE_ARRAY(1, 7))) ones;

huangapple
  • 本文由 发表于 2023年6月8日 17:38:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430512.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定