【问题标题】:Json extraction using postgres [duplicate]使用postgres提取Json [重复]
【发布时间】:2021-05-12 03:33:34
【问题描述】:

我有一个json

{
  "timer": {
    "19272": {
      "asset_id": 9354,
      "original_total_time": 5,
      "original_warning_time": null
    }
  },
  "SEBKeys": [],
  "scoreMappings": []
}

我需要使用 Postgres 从这个 json 中提取“original_total_time”值。

谁能帮忙?

【问题讨论】:

  • 如果你使用 PHP,你可以使用json_decode()
  • 有什么方法可以让我自己查询吗?
  • 你的 JSON 结构是固定的还是动态的
  • 我得到了解决方案 (SELECT * , requests.request -> 'notes' -> json_object_keys((requests.request ->> 'notes')::json) ->> 'message' AS来自请求的消息)

标签: php json postgresql json-extract


【解决方案1】:

如果您的 JSON 结构是固定的,那么您可以使用以下查询

select json_->'timer'->'19272'->>'original_total_time' from test

DEMO

【讨论】:

    猜你喜欢
    • 2021-02-15
    • 2020-11-26
    • 2022-01-05
    • 1970-01-01
    • 2018-08-06
    • 2014-03-07
    • 1970-01-01
    • 2012-06-13
    • 2021-03-31
    相关资源
    最近更新 更多