Re: Using JSONB with nested key-value structures, andskipping/wildcarding the key - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Using JSONB with nested key-value structures, andskipping/wildcarding the key
Date
Msg-id FB580CA8-7660-4579-9165-9AEDACA12957@gmail.com
Whole thread Raw
In response to Re: Using JSONB with nested key-value structures, andskipping/wildcarding the key  (Shaheed Haque <shaheedhaque@gmail.com>)
List pgsql-general
> On 2 Jun 2020, at 9:30, Shaheed Haque <shaheedhaque@gmail.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/impossibleto use from the ORM (barring a full scale escape to a "raw" query). One question: as a novice here, I
thinkI 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
itreturns 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.




pgsql-general by date:

Previous
From: Paul Förster
Date:
Subject: Re: Patroni
Next
From: Tom Lane
Date:
Subject: Re: Fine grained permissions on User Mapping