Re: Is it possible to index "deep" into a JSONB column?

From: Shaheed Haque <shaheedhaque(at)gmail(dot)com>
To: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
Cc: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Is it possible to index "deep" into a JSONB column?
Date: 2022-05-30 08:18:29
Message-ID: CAHAc2jeAnFNcTJ-wJtQmxjfjJKgTorX+LQDuPBamQxuxMLcptw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Bryn,

On Mon, 30 May 2022 at 03:12, Bryn Llewellyn <bryn(at)yugabyte(dot)com> wrote:
...
>
> Try this:
>
> snapshot -> ‘employee’->>’date_of_birth’
>

Syntactically, that works:

create index bryn on paiyroll_payrun using btree ((snapshot ->
'employee'->>'date_of_birth'));

But IIUC it is looking for 'date_of_birth' in the wrong level. it
would need to do something like this:

create index bryn on paiyroll_payrun using btree ((snapshot ->
'employee'->'2209'->>'date_of_birth'));

To paraphrase, my question is about how to replace the '2209' with all
possible object keys. For the employee-is-an-array, the documentation
says this should work:

create index bryn2 on paiyroll_payrun using btree ((snapshot ->
'employee[*]'->>'date_of_birth'));

but is silent on the employee-is-an-object case. (As I said, in case
it helps, in my case the keys are in fact stringified numbers).

Thanks, Shaheed

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Fabien COELHO 2022-05-30 09:05:48 Re: psql 15beta1 does not print notices on the console until transaction completes
Previous Message Masahiko Sawada 2022-05-30 06:52:29 Re: Support logical replication of DDLs