From: David Gauthier <davegauthierpg@gmail.com>
To: Postgres General <pgsql-general@postgresql.org>
Subject: Wildcarding json keys in json query
Date: Tue, 30 Nov 2021 15:40:10 -0500
Message-ID: <CAMBRECCKusTv=uNUp6JoBjvHog1vutf3gqO2gFJ__xgamCBFrw@mail.gmail.com> (raw)
PG 11.5 on linux
Let's say I store a jsonb in a column called test_results that looks like
this...
{
ports : {
port_abc:{min: 5, max: 7, mean: 6},
port_def:{min: 5, max: 9, mean: 7},
port_ghi:{min: 6, max: 10, mean: 8}
}
}
And I want to to get all the port names where the mean is >= 7.
This works...
select 1 from mytbl where cast(test_results#>'{ports,*port_abc*,mean}' as
float) >= 7 ;
But I want *all *the ports that have mean >= 7.
Something akin to...
select 1 from mytbl where cast(test_results#>'{ports,***,mean}' as float)
>= 7 ;
But the "*" doesn't work :-(
Any ideas ?
Thanks!
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: davegauthierpg@gmail.com
Subject: Re: Wildcarding json keys in json query
In-Reply-To: <CAMBRECCKusTv=uNUp6JoBjvHog1vutf3gqO2gFJ__xgamCBFrw@mail.gmail.com>
References: <CAMBRECCKusTv=uNUp6JoBjvHog1vutf3gqO2gFJ__xgamCBFrw@mail.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