pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Using vars in jsonbpath operator ?
Date: Fri, 16 Jun 2023 15:24:54 +0200
Message-ID: <39a04bd8-aefd-b02e-594b-ca875a884048@gmx.net> (raw)
In-Reply-To: <4A219290-0DC1-4782-85F6-55CA334192C3@gmail.com>
References: <4A219290-0DC1-4782-85F6-55CA334192C3@gmail.com>



Markur Sens schrieb am 16.06.2023 um 13:54:
> I understand that on a where clause a gin index can be used for the following predicate
>
> a.data @? '$.results.docs[*].accs[*] ? (@.id == “123")
>
> I have a join query however on the following condition
>
> jsonb_path_exists(a.data, '$.results.docs[*].accs[*] ? (@.number == $id)', jsonb_build_object(‘id', *b.id*))  but this cannot use a gin index afaik and results in a seq scan.
>
> Is there anyway to use the operator syntax above by passing the b.id <http://b.id> variable somwehow so that the gin index can be used ? ? 
>

I think you will need to pass the whole jsonpath as a parameter, e.g.


    a.data @? cast($1 as jsonpath)


At least that's the only way I could achieve this









view thread (2+ messages)

Message-ID: <39a04bd8-aefd-b02e-594b-ca875a884048@gmx.net>
Permalink:  ../39a04bd8-aefd-b02e-594b-ca875a884048@gmx.net/
Also on:    postgresql.org/message-id/39a04bd8-aefd-b02e-594b-ca875a884048@gmx.net

 · 

reply

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: shammat@gmx.net
  Subject: Re: Using vars in jsonbpath operator ?
  In-Reply-To: <39a04bd8-aefd-b02e-594b-ca875a884048@gmx.net>
  References: <4A219290-0DC1-4782-85F6-55CA334192C3@gmail.com> <39a04bd8-aefd-b02e-594b-ca875a884048@gmx.net>

* 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