Your Location is: Home > Postgresql-9.5

Can't hide node “data”

From: United View: 3692 a_subscriber 

Question

Column data is 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

and here result as array:

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

Nice. But... I need to hide node data.

The result must be

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

Is it possible?

Best answer

you should be able to perform a second select on the result. then specificaly select data

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

example