pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedUsing vars in jsonbpath operator ?
2+ messages / 2 participants
[nested] [flat]
* Using vars in jsonbpath operator ?
@ 2023-06-16 11:54 Markur Sens <markursens@gmail.com>
2023-06-16 13:24 ` Re: Using vars in jsonbpath operator ? Thomas Kellerer <shammat@gmx.net>
0 siblings, 1 reply; 2+ messages in thread
From: Markur Sens @ 2023-06-16 11:54 UTC (permalink / raw)
To: pgsql-general <pgsql-general@lists.postgresql.org>
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 ? ? =
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Using vars in jsonbpath operator ?
2023-06-16 11:54 Using vars in jsonbpath operator ? Markur Sens <markursens@gmail.com>
@ 2023-06-16 13:24 ` Thomas Kellerer <shammat@gmx.net>
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Kellerer @ 2023-06-16 13:24 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2023-06-16 13:24 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 11:54 Using vars in jsonbpath operator ? Markur Sens <markursens@gmail.com>
2023-06-16 13:24 ` Thomas Kellerer <shammat@gmx.net>
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