| From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
|---|---|
| To: | Alex Magnum <magnum11200(at)gmail(dot)com> |
| Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Extract data from JSONB |
| Date: | 2016-08-08 03:23:38 |
| Message-ID: | CAB7nPqSO=GuLOnc9VZkaq1-aRDAtEAom3DGVFL9UMKr6HwfBDg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Mon, Aug 8, 2016 at 12:08 PM, Alex Magnum <magnum11200(at)gmail(dot)com> wrote:
> How can I convert that into one row each based on status; for example if I
> only want to have the active modules.
You can use jsonb_each to decompose that:
=# select key, (value::json)->'status' from jsonb_each('{
"accounts":
{"status": true},
"admin": {"status": true},
"calendar": {"status": false},
"chat": {"status": true},
"contacts": {"status": true},
"dashboard": {"status": false},
"help": {"status": true}}'::jsonb);
key | ?column?
-----------+----------
chat | true
help | true
admin | true
accounts | true
calendar | false
contacts | true
dashboard | false
(7 rows)
--
Michael
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Charles Clavadetscher | 2016-08-08 04:54:44 | Re: Extract data from JSONB |
| Previous Message | Alex Magnum | 2016-08-08 03:08:08 | Extract data from JSONB |