snowflake-cloud-data-platform - 雪花 - 未嵌套列出现错误:无效参数 > 函数类型
问题描述
我在“BTR”中有一个 MONTHLY_BUDGETS 列,看起来像这样。“IO_LINMS”:
[{"id": 11, "quantity_booked": "12", "budget_booked": "0.0",
"budget_booked_loc": "0.0", "quantity_delivered": "22",
"budget_delivered": "0.0", "actual_cost_loc": "0.0"}]
我已经尝试过以下方法:
SELECT
MONTHLY_BUDGETS[0]:id::integer as monthly_budgets_id
from "BTR"."IO_LINMS"
但我收到此错误:
SQL 编译错误:位置 15 处的错误行 2 函数 'GET' 的参数类型无效:(VARCHAR(16777216), NUMBER(1,0))
解决方案
您需要嵌入parse_json
到lateral flatten
您的 SQL 中。
需要横向展平,因为您的数据结构是一个数组。
以下代码将为您提供示例数据中的 id
with d as (select parse_json('[{"id": 1590482}]') m)
select v.value:id::integer as monthly_budgets_id
from d, lateral flatten(input => m) v
推荐阅读
- excel - 从 Excel 宏创建数据透视图
- python - 如何有效地删除所有数字作为 pandas 上的数据清理?
- c# - 当方法返回类型 IEnumerable 时,方法返回 List。但 GetType 显示为 List
- html - 输入字段宽度不受边距影响
- android-studio - 安装失败并显示消息 Failed to finalize session : INSTALL_PARSE_FAILED_NO_CERTIFICATES
- php - 如何使用来自 PhpStorm 的 .htaccess 文件?
- javascript - Hoare 快速排序算法无法正常工作
- rust - 不能在循环中多次借用可变错误
- image - 在Linux中使用file命令的输出分析图像导致Linux shell脚本错误?
- scala - 如何确定问题是否可以在 Scala 中使用尾递归解决