snowflake-cloud-data-platform - 雪花从具有嵌套字典列表的列中获取每个键/值
问题描述
我有一个名为monthly_stats(VARCHAR 类型)的列,其中包含以下字典列表:
[{"id": 123, "quantity_booked": "12", "budget_booked": "112", "budget_booked_loc": "36.428571"},
{"id": 1288119, "quantity_booked": "1703.3", "budget_booked": "58.694684",
"budget_booked_loc": "43.434066"}, {"id": 233, "quantity_booked": "1648.35",
"budget_booked": "56.801307", "budget_booked_loc": "42.032967"}]
我试过这个查询:
with org_table as (
select
parse_json(monthly_stats) as m
from my_table
)
select
m[0]:id::integer as monthly_budgets_id,
from org_table);
但这只会选择字典列表中的第一个 id。如何获取每个字典中的每个 id?
解决方案
你可以这样尝试lateral flatten
:
set teststring = '[{"id": 123, "quantity_booked": "12", "budget_booked": "112", "budget_booked_loc": "36.428571"},
{"id": 1288119, "quantity_booked": "1703.3", "budget_booked": "58.694684", "budget_booked_loc": "43.434066"}]';
with org_table as (
select
parse_json($teststring) as m
)
select
flattened.value:id as id
from org_table,
lateral flatten( input => m ) as flattened;
推荐阅读
- node.js - 从帖子获取重定向不会导致查看更新
- html - Angular Flex 不能将项目放在同一行,Angular 8.2.1 和 Flex-Layout 8.0.0.beta 26
- javascript - 反应:无法通过将函数传递给更新它的子组件来更新父状态
- android - 如何修复屏幕锁定后Android MediaPlayer自动关闭
- python - 从python中的daraframe创建数据框列表
- c# - 通过 Wifi Lan 连接将数据从 Desktop Sqlite DB 检索到 android 应用程序
- c++ - 循环动态数组重新分配(通过`new`构造函数)导致`segmentation fault`-malloc错误
- amazon-web-services - AWS 或 Azure 上 SQL+Web App+SSIS+SSRS 的最佳解决方案是什么
- c# - 具有不同命令和反馈单元/类型的 PID(比例-积分-微分控制器)回路
- algorithm - 优化自定义数据编码的比特浪费