首页 > 解决方案 > 雪花 - 未嵌套列出现错误:无效参数 > 函数类型

问题描述

我在“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))

标签: snowflake-cloud-data-platform

解决方案


您需要嵌入parse_jsonlateral 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


推荐阅读