Re: Wildcarding json keys in json query

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: David Gauthier <davegauthierpg(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Wildcarding json keys in json query
Date: 2021-12-01 00:17:00
Message-ID: CAKFQuwZ6P9+YaaW0A9WCCVgUn1RZfWr2c5LhU6HJT5pEiOarhg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Nov 30, 2021 at 1:40 PM David Gauthier <davegauthierpg(at)gmail(dot)com>
wrote:

> {
> 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}
> }
> }
>
> select 1 from mytbl where cast(test_results#>'{ports,***,mean}' as float)
> >= 7 ;
>
> But the "*" doesn't work :-(
>
> Any ideas ?
>
>
If you have the option to not use data values in json field identifiers
(i.e., object keys) you will avoid fighting against the system's underlying
design choices. i.e., IMO, ports should contain an array, not an object.

I was under the impression that SQL/JSON Path (jsonpath)
functions/operators solve some of these kinds of problems so try using that
instead of the "fixed structure" access-based functions and operators.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Saurav Sarkar 2021-12-01 03:08:13 Re: Database Scalability
Previous Message Yi Sun 2021-11-30 23:46:01 Re: ssl_crl_file Certificate Revocation List doesn't work for postgresql 11