From: Alban Hertroys <haramrae@gmail.com>
To: Shaheed Haque <shaheedhaque@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Using JSONB with nested key-value structures, and skipping/wildcarding the key
Date: Tue, 2 Jun 2020 14:20:20 +0200
Message-ID: <FB580CA8-7660-4579-9165-9AEDACA12957@gmail.com> (raw)
In-Reply-To: <CAHAc2jcrVBSeRfauX1rSEiMUMU1TcG5W5nNm6wypjV7q+b60ng@mail.gmail.com>
References: <CAHAc2jdUVXz+G6h82vMBVVsvr98a-eNsd7yfwz3Muva5UaajQg@mail.gmail.com>
<960EE185-1107-4BB8-9D10-4F7ECAC923B2@gmail.com>
<CAHAc2jcrVBSeRfauX1rSEiMUMU1TcG5W5nNm6wypjV7q+b60ng@mail.gmail.com>
> 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/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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: haramrae@gmail.com, shaheedhaque@gmail.com
Subject: Re: Using JSONB with nested key-value structures, and skipping/wildcarding the key
In-Reply-To: <FB580CA8-7660-4579-9165-9AEDACA12957@gmail.com>
References: <CAHAc2jdUVXz+G6h82vMBVVsvr98a-eNsd7yfwz3Muva5UaajQg@mail.gmail.com> <960EE185-1107-4BB8-9D10-4F7ECAC923B2@gmail.com> <CAHAc2jcrVBSeRfauX1rSEiMUMU1TcG5W5nNm6wypjV7q+b60ng@mail.gmail.com> <FB580CA8-7660-4579-9165-9AEDACA12957@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox