Re: Using JSONB with nested key-value structures, and skipping/wildcarding the key

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Shaheed Haque <shaheedhaque(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Using JSONB with nested key-value structures, and skipping/wildcarding the key
Date: 2020-06-02 12:20:20
Message-ID: FB580CA8-7660-4579-9165-9AEDACA12957@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On 2 Jun 2020, at 9:30, Shaheed Haque <shaheedhaque(at)gmail(dot)com> wrote:
>
>
>> I do something like this to get a set of sub-paths in a JSONB field (no idea how to write that in Django):
>>
>> select snapshot->’pay_definition’->k.value->’name’
>> from MyModel
>> join lateral jsonb_object_keys(snapshot->’pay_definition’) k(value) on true
>>
> I was unaware of the LATERAL keyword, so thanks. After a bit of Googling however, it seems that it is tricky/impossible to use from the ORM (barring a full scale escape to a "raw" query). One question: as a novice here, I think I understand the right hand side of your JOIN "... k(value)" is shorthand for:
>
> ... AS table_name(column_name)
>
> except that I don't see any clues in the docs that jsonb_object_keys() is a "table function". Can you kindly clarify?

Correct. Thomas already explained the return type, but the plural form of the function name is also an indication that it returns multiple results.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2020-06-02 14:08:26 Re: Fine grained permissions on User Mapping
Previous Message Paul Förster 2020-06-02 12:11:40 Re: Patroni