sql >> Database >  >> RDS >> PostgreSQL

Geaggregeerde som van json-array ophalen in Postgres NOSQL json-gegevens

Dit zou moeten werken op 9.3+

WITH x AS( SELECT
'{
  "id": "tran_6ac25129951962e99f28fa488993",
  "amount": 1200,
  "origin_amount": 3900,
  "status": "partial_refunded",
  "description": "Subscription#sub_a67d59efb2bcbf73485a ",
  "livemode": false,
  "refunds": [
    {
      "id": "refund_ee4192ffb6d2caa490a1",
      "amount": 1200,
      "status": "refunded",
      "created_at": 1426412340,
      "updated_at": 1426412340
    },
    {
      "id": "refund_0e4a34e4ee7281d369df",
      "amount": 1500,
      "status": "refunded",
      "created_at": 1426412353,
      "updated_at": 1426412353
    }
  ]
}'::json as y),
refunds AS(
SELECT json_array_elements(y->'refunds') as j FROM x)
SELECT sum((j->>'amount')::int) FROM refunds;


  1. Wat is het verschil tussen het 'yy'- en 'rr'-datummasker van orakel?

  2. Meerdere OUTPUT-clausules in MERGE/INSERT/DELETE SQL-opdrachten?

  3. Equivalent van GroupBy en Having-clausule in relationele algebra

  4. Docker MySQL - kan geen verbinding maken vanuit de Spring Boot-app naar de MySQL-database