我在“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))
答案 0 :(得分:0)
您需要在 SQL 中加入 parse_json
和 lateral flatten
。
需要横向展平,因为您的数据结构是一个数组。
以下代码将为您提供示例数据中的 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