简体   繁体   English

POSTGRESQL 查询以提取 JSON 中的属性

[英]POSTGRESQL query to extract attributes in JSON

I have the below JSON in a particular DB column.我在特定的数据库列中有以下 JSON。 I need a query to extract fields stored within the savings rate(to and from) .我需要一个查询来提取存储在savings rate(to and from)中的字段。

 {
  "data": [
    {
      "data": {
        "intro_visited": {
          "portfolio_detail_investment_journey": true,
          "dashboard_investments": true,
          "portfolio_list_updates": true,
          "portfolio_detail_invested": true,
          "portfolio_list_offering": true,
          "dashboard_more_bottom_bar": true
        }
      },
      "type": "user_properties",
      "schema_version": "1"
    },
    {
      "data": {
        "savings_info": {
          "remind_at": 1583475493291,
          "age": 100,
          "savings_rate": {
            "to": "20",
            "from": "4"
          },
          "recommendation": {
            "offering_name": "Emergency Fund",
            "amount": "1,11,111",
            "offering_status": "not_invested",
            "ideal_amount": "1,11,111",
            "offering_code": "liquid"
          }
        }
      },
      "type": "savings_info",
      "schema_version": "1"
    }
  ]
}

To get the "To"得到“到”

$..data.savings_info.savings_rate.to

To get the "From"获取“来自”

$..data.savings_info.savings_rate.from

This script works这个脚本有效

SELECT 
<column> ->'data'->2->'data'->'savings_info'->'savings_rate'->>'to' AS to_rate
from <table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM