【问题标题】:extract json array data from json column in postgres从postgres中的json列中提取json数组数据
【发布时间】:2020-07-04 03:55:30
【问题描述】:

谁能帮助我如何从这个选择查询中提取存储在“TimeCounterTotals”列中的 json 数组数据?当我将硬编码数据传递给 json_to_recordset 函数时,它工作正常,但如何在选择查询中执行?

select "CompanyId", json_to_recordset("TimeCounterTotals") as x("TimeTotal" decimal, "TimeCounterId" varchar)
from "TimeCalculationAndApprovals" where "TimeCounterTotals" is not null limit 1;

【问题讨论】:

    标签: c# .net postgresql


    【解决方案1】:

    不完全确定你想要什么,但作为一个开始:

    create table json_test(id integer, fld_json json);
    insert into json_test values (1, '[{"a":1,"b":"foo"},{"a":2,"b":"bar"}]'::json), (2, '[{"a":3,"b":"test"},{"a": 4,"b":"test2"}]'::json); 
    
    select id, a, b from json_test, json_to_recordset(json_test.fld_json) as x(a integer, b varchar);
     id | a |   b   
    ----+---+-------
      1 | 1 | foo
      1 | 2 | bar
      2 | 3 | test
      2 | 4 | test2
    
    

    【讨论】:

      猜你喜欢
      • 2018-07-10
      • 2020-10-14
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 2021-11-20
      相关资源
      最近更新 更多