Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ms9vQ-0001NF-KS for pgsql-general@arkaria.postgresql.org; Tue, 30 Nov 2021 20:40:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ms9vP-0002rR-Hd for pgsql-general@arkaria.postgresql.org; Tue, 30 Nov 2021 20:40:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ms9vP-0002rI-5g for pgsql-general@lists.postgresql.org; Tue, 30 Nov 2021 20:40:27 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ms9vL-0006t5-Tp for pgsql-general@postgresql.org; Tue, 30 Nov 2021 20:40:26 +0000 Received: by mail-oi1-x233.google.com with SMTP id bj13so43747331oib.4 for ; Tue, 30 Nov 2021 12:40:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=oA2+c31Cx19ut2h3Cw/mV9dvEb82ASlLec0IIsoZeqQ=; b=FtQsLT3TOTwJ2H4teeYRDo5GG8VNq8A6XYczLhjXPpXgsZzCJPea7MsqWCRvLmzZH4 iO2K59R6+kHaZ9TJiP2lE6clTxq2dbh/SkXK9KDnAhQsEI0U4zYgfMQ8j5iPpFUEIYR4 M+erQ2ZE61AI+U+zT+q7i1Bx8lhWmGD1tVfNGAZy1N3f3vQJ+wFgGb3r0dAZbEqu3KU/ zdqF9UGqRtX82o4Vu1hpIu7GOP8mA4YalxJGyEq/Yjv0j7BuH0kVK+apFzbVxIbAyBZx TaWo/rMUBuK+FqAJF5k2/rnv3txFxFKNDx7793+7OJFAgkZbstaAb5dtnhn3+fa2lvc7 mp+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=oA2+c31Cx19ut2h3Cw/mV9dvEb82ASlLec0IIsoZeqQ=; b=W8rXISpDthTnn9D+VmyeixAj1A81DaK9vWoVxwlz5ORqL17raWwT/2EPrAI5SP282M SxvSNbNYPQ8NR0wYX6qQYOTRbm+qxVZr3jRGilTXFLPhQW4qS8IP4jG/2v4cW5o2Ni1m ue0AXLRXfh0mYCr0iAbAHw10zUXDdOVHjV691L5KiGi/sT92XZ1Bphh0U/DwsuKGCJJr bZ7voFLCKC/jW2OmV7SMsuvWKcfrE/JDxLi9il2iXlq4F6N7X+JxcS2PPHzbChV7E6dK mulIK/i7BXmGmLMUHq1XPOydIE+FFVBKFRDmVMfGFeUjQ8atunLDT6SoRz0O7DHixKho /zdw== X-Gm-Message-State: AOAM531S3xNS9QxKpanV2ibi8nsXf98783CeXWIvUr2aZj4kywW/JF10 A1UsspRqIPeYrbmQeoDyrZMRG8iGYIWPlEbwGpuVxG6d0UAGSg== X-Google-Smtp-Source: ABdhPJw4DtID2PRe3ZKk6uX/XPNVhi54jIQ4DNg8fyHWAg1y1ApEF4ygWcgTFgvODH4HSokXcow+HGVgDhkTsdpiGJw= X-Received: by 2002:a05:6808:14ce:: with SMTP id f14mr1349041oiw.162.1638304821866; Tue, 30 Nov 2021 12:40:21 -0800 (PST) MIME-Version: 1.0 From: David Gauthier Date: Tue, 30 Nov 2021 15:40:10 -0500 Message-ID: Subject: Wildcarding json keys in json query To: Postgres General Content-Type: multipart/alternative; boundary="000000000000f0f57f05d2079056" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f0f57f05d2079056 Content-Type: text/plain; charset="UTF-8" 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! --000000000000f0f57f05d2079056 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
PG 11.5 on linux

Let's say I store a jsonb=C2=A0in = a column called test_results that looks like this...

{
ports : {
= =C2=A0 =C2=A0 port_abc:{min: 5, max: 7, mean: 6},
=C2=A0 =C2=A0 port_def:{= min: 5, max: 9, mean: 7},
=C2=A0 =C2=A0 port_ghi:{min: 6, max: 10, mea= n: 8}
=C2=A0 =C2=A0 }
}

And I want to to get all the port name= s where the mean is >=3D 7.

This works...

select 1 from = mytbl where cast(test_results#>'{ports,po= rt_abc,mean}' as float) >=3D 7 ;

But I want all the ports that have mean >=3D 7.
Something akin to...
=
select 1 from mytbl where cast(test_resu= lts#>'{ports,*,mean}' as f= loat) >=3D 7 ;

<= div class=3D"gmail_default" style=3D"font-family:monospace,monospace">But t= he=C2=A0"*" doesn't work :-(

Any ideas ?
Thanks!
--000000000000f0f57f05d2079056--