Snowflake SQL如何打开阵列
在Snowflake数据库中,我有一张桌子上有一个数组列。 大多数pf时数阵列中只有1个值,但最多可达100。 我正在尝试打开将为每个单元格提供不同原始的数组。
这是表中一行的一个示例:
"currencies_added":[{"Gems": 24000},{"Gems": 1250}]
尝试使用“ Flatten”函数,但是每次都会出现错误:
单行子查询返回一行以上。
例如:
select *
from FISH_OF_FORTUNE_DEV.DWH.FACT_DAILY_REVENUE,
table(flatten (
select currencies_added
from FISH_OF_FORTUNE_DEV.DWH.FACT_DAILY_REVENUE
) )f ;
请参阅图像: 数据库中的行
In Snowflake Database, I've got a table where I got an array column.
most pf the times there is only 1 value in the array, but can be up to 100.
I'm trying to open the array that will give each cell a different raw.
Here is an example of a single row in the table:
"currencies_added":[{"Gems": 24000},{"Gems": 1250}]
Tried using "flatten" function, but each time I get an error:
Single-row subquery returns more than one row.
For example:
select *
from FISH_OF_FORTUNE_DEV.DWH.FACT_DAILY_REVENUE,
table(flatten (
select currencies_added
from FISH_OF_FORTUNE_DEV.DWH.FACT_DAILY_REVENUE
) )f ;
see image:
Rows in database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设这些数组存储在变体列或数组中,并且已被解析为JSON,则需要使用横向变平。该代码使用CTE使用您提供的相同提供的,而不是表:
我查询中的输出:
Assuming these arrays are stored in a variant columns or arrays and have been parsed as JSON, you'd want to use a lateral flatten. This code uses a CTE to use your same provided, rather than a table:
Output in my query:
添加到@mike,使用
Flatten
的更多示例。使用以下数据集的原始形式(无扁平) -
仅扁平列 -
扁平以获取数组(将产生两个行,对应于两个数组元素) -
平坦的数组元素 -
,您可以,您可以使用
递归
子句 -使用AS AS仅数组 -
Adding to @Mike, few more examples of using
FLATTEN
.Using below data-set in original form (no flatten) -
Flatten only the column -
Flatten to get the array (will produce two rows, corresponding to two array elements) -
Flatten array elements -
OR, you can use
recursive
clause -Using as array only -