Re: postgres json: How to query map keys to get children

From: Hector Menchaca <hm34306(at)hotmail(dot)com>
To: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: postgres json: How to query map keys to get children
Date: 2014-08-23 23:38:39
Message-ID: BAY178-W418B5250FE53F5D2D6514DF8D10@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Perfect your snippet gave me some clues...
It looks as follows:
SELECT json_array_elements(skill_type.Skill->'value')->>'Name' as NameFROM ( SELECT to_json(json_each(ResourceDocument->'Skill')) as Skill FROM testdepot.Resource) skill_type
to_json returns a key value map which you then use to get to the json array
Thanks for the lead :)
> Date: Sat, 23 Aug 2014 13:18:52 -0700
> From: david(dot)g(dot)johnston(at)gmail(dot)com
> To: pgsql-sql(at)postgresql(dot)org
> Subject: Re: [SQL] postgres json: How to query map keys to get children
>
> Hector Menchaca wrote
> > json_array_elements(ResourceDocument->'Skill'->*)
>
> NOT TESTED (or complete)
>
> SELECT skill_type.value->'Name'
> FROM (
> SELECT * FROM json_each(rd->'Skill')
> ) skill_type
>
> Because you want columns for Name, etc, you must list those explicitly
> instead of using json_each over those.
>
> David J.
>
>
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/postgres-json-How-to-query-map-keys-to-get-children-tp5816001p5816009.html
> Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Kellerer 2014-08-25 05:59:18 Re: Retrieve most recent 1 record from joined table
Previous Message David G Johnston 2014-08-23 20:18:52 Re: postgres json: How to query map keys to get children