retrieve subset of a jsonb object with a list of keys

From: Tom Smith <tomsmith1989sk(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: retrieve subset of a jsonb object with a list of keys
Date: 2015-08-19 11:37:02
Message-ID: CAKwSVFHk+m16ouvymp1mMPq4LU1hpdFhJ-=05nU3kumdPxx4-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi:

I have a jsonb columne with json object like belo
{"a": 1, "b":2, "c":3}

I'd like to get subset of the object with key list ["a","c"]
so it retruns json object of

{"a": 1, "c":3}

something like

select '{"a": 1, "b":2, "c":3}'::jsob ->'["a","c"]'

what would be the most efficient (and simplest if possible) to get the
subset with the key list?

Thanks

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Mair 2015-08-19 13:46:14 Re: retrieve subset of a jsonb object with a list of keys
Previous Message tonymark09 2015-08-19 10:55:06 Preparing statement using PQexec vs PQprepare