gpt4 book ai didi

json - 从 Snowflake 卸载数据时将 OBJECT_CONSTRUCT 结果嵌套在 JSON 数组中

转载 作者:行者123 更新时间:2023-12-04 20:02:37 25 4
gpt4 key购买 nike

我正在使用 OBJECT_CONSTRUCT在具有多行的表上,如下所示:

COPY INTO @%mytable
FROM (
SELECT OBJECT_CONSTRUCT(
'id', id, 'first_name', first_name,
'last_name', last_name, 'city', city, 'state', state
) FROM mytable
)
FILE_FORMAT = (TYPE = JSON);

这会产生以下类型的 JSON 输出:
{"city":"Salt Lake City","first_name":"Ryan","id":1,"last_name":"Dalton","state":"UT"}
{"city":"Birmingham","first_name":"Upton","id":2,"last_name":"Conway","state":"AL"}
{"city":"Columbus","first_name":"Kibo","id":3,"last_name":"Horton","state":"GA"}

但是,我想将生成的对象嵌套到 JSON 数组中,如下所示:
[
{"city":"Salt Lake City","first_name":"Ryan","id":1,"last_name":"Dalton","state":"UT"},
{"city":"Birmingham","first_name":"Upton","id":2,"last_name":"Conway","state":"AL"},
{"city":"Columbus","first_name":"Kibo","id":3,"last_name":"Horton","state":"GA"}
]

这可能吗?

最佳答案

我目前无法访问雪花帐户,因此对于未经测试的解决方案,我深表歉意:( 我认为您正在寻找 array_construct,您可以阅读 about here

我希望这样的事情可以工作

COPY INTO @%mytable
FROM (
SELECT ARRAY_CONSTRUCT(objs)
FROM (
SELECT OBJECT_CONSTRUCT(
'id', id, 'first_name', first_name,
'last_name', last_name, 'city', city, 'state', state
) as objs FROM mytable
)
)
FILE_FORMAT = (TYPE = JSON);

关于json - 从 Snowflake 卸载数据时将 OBJECT_CONSTRUCT 结果嵌套在 JSON 数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52853048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com