Re: Wildcarding json keys in json query - Mailing list pgsql-general

From David G. Johnston
Subject Re: Wildcarding json keys in json query
Date
Msg-id CAKFQuwZ6P9+YaaW0A9WCCVgUn1RZfWr2c5LhU6HJT5pEiOarhg@mail.gmail.com
Whole thread Raw
In response to Wildcarding json keys in json query  (David Gauthier <davegauthierpg@gmail.com>)
List pgsql-general
On Tue, Nov 30, 2021 at 1:40 PM David Gauthier <davegauthierpg@gmail.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.

pgsql-general by date:

Previous
From: Yi Sun
Date:
Subject: Re: ssl_crl_file Certificate Revocation List doesn't work for postgresql 11
Next
From: Saurav Sarkar
Date:
Subject: Re: Database Scalability