【问题标题】:Can't hide node "data"无法隐藏节点“数据”
【发布时间】:2020-11-04 14:04:52
【问题描述】:

data 列是 jsonb

 SELECT 
    json_agg(shop_order)
    FROM (
    SELECT data from shop_order 
        WHERE  data->'contacts'->'customer'->>'phone' LIKE '%1234567%' LIMIT 3 OFFSET 3 
    ) shop_order

这里的结果是数组:

[
  {
      "data": {
        "id": 211111,
        "cartCount": 4,
        "created_at": "2020-10-28T12:58:33.387Z",
        "modified_at": "2020-10-28T12:58:33.387Z"
      }
   }
  ]

很好。但是...我需要隐藏节点 data

结果必须是

[
  {
        "id": 211111,
        "cartCount": 4,
        "created_at": "2020-10-28T12:58:33.387Z",
        "modified_at": "2020-10-28T12:58:33.387Z"
      }
   
      ]

有可能吗?

【问题讨论】:

  • select jsonb_agg(to_jsonb(data)) from shop_order ... 呢?
  • @a_horse_with_no_name 是的,这很有帮助。谢谢

标签: postgresql-9.5


【解决方案1】:

您应该能够对结果执行第二次选择。然后专门选择数据

SELECT (result->>'data') as result,
FROM result

example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 2022-07-27
    • 2013-02-18
    相关资源
    最近更新 更多