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 1mxt7y-0005um-Uh for pgsql-novice@arkaria.postgresql.org; Thu, 16 Dec 2021 15:57:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxt7x-0002tG-ST for pgsql-novice@arkaria.postgresql.org; Thu, 16 Dec 2021 15:57:05 +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 1mxt7x-0002t7-I7 for pgsql-novice@lists.postgresql.org; Thu, 16 Dec 2021 15:57:05 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mxt7u-00040d-JE for pgsql-novice@lists.postgresql.org; Thu, 16 Dec 2021 15:57:05 +0000 Received: by mail-io1-xd30.google.com with SMTP id m9so35877795iop.0 for ; Thu, 16 Dec 2021 07:57:02 -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=cj6L36TDPFZzDUtmskqIHwqnKcu+yRZsb27JdSzhQMc=; b=VpHgpPlCt7mSpCUfcsvZy5nLPbnOIrtD9IArLkU00bp9Gjh8s2Nn9IMbpzJVlOBfi4 At/JOP/LodW2lIGIGVd86WBRzZX2ZUv/NdqbJvRYqPbGf1yzkrXTonGruADbGy39mlwe PYlsyomrk+sezOzjeCandbFxpVKF2XR519ECgFNj7XWNrbrCIb8YQ42YrA5+oq69/PKN qxLPErxW2i4E/v304HCqUR5tTWD7rEnhFkW6qY5tcAZzPMdMs/QwrM2jIiSepha4d38o 9xekrL8JSO7DNMeKQhreiQK2ru3liHufRolk49g7GMmFd8bUsAx0R9Mx3jCuZDXpPjly 1xsA== 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=cj6L36TDPFZzDUtmskqIHwqnKcu+yRZsb27JdSzhQMc=; b=dWkHEHw6MHi0KabC/YRYV7UxdNZ06RmwUt7s194RAVziFr5LZ1unMhC0kL8WzJmTOP rGimAQEs0lVHdKjB4zuMimgWai57gwp9XVrNwKXLBjD2ExO7D6rKRG0S1JzaEGFq0Wbw eXQHyM2xOnUP4V9kMfdTOMwR46L6eSzmmRQfrBN7VHGtYLuAWb+9ymknw+8FXenN6DYC 3QCig9ndZ57zrQW+RKJjdoP2O5kayMxHDQhThu5ddXd1IZszvwBdySIux7abc02dYbl7 kFkqb6XakRmgyeTqGbTtlQ/jRhW/sxTN5syMX5DufELMzPkAk4r4XbWT36Px0HWTIc0T lL/w== X-Gm-Message-State: AOAM530DxL2sCA8JDofeaNzUL+zxDZ93Ae/aZSmErcSYZZCGjgCbhGCP eGA+BGv3ItMSjI70H5ELygTt1DHdyaQfhNll2Pv3v8VJKYI= X-Google-Smtp-Source: ABdhPJzkz3WEz4l+VS6UOzUY0unz85iiQUIbl/+vS2NiM74kN2wiWoSPzAnsZHAm/IznCR8gfELkKW2uLyU3oNZo2Ls= X-Received: by 2002:a05:6638:d4e:: with SMTP id d14mr9518540jak.309.1639670219974; Thu, 16 Dec 2021 07:56:59 -0800 (PST) MIME-Version: 1.0 From: Alex R Date: Thu, 16 Dec 2021 16:56:48 +0100 Message-ID: Subject: JSONpath query that returns paths to the matches To: pgsql-novice@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000002ab8a05d3457911" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000002ab8a05d3457911 Content-Type: text/plain; charset="UTF-8" Hi, I am trying to figure out whether Postgres 14 allows me to find the paths to certain values in the JSON, rather than the values themselves. To illustrate, here is a test query: SELECT JSONB_PATH_QUERY($${ "this": "that", "that": [{"x": "aaa"},{"y": "missed"}], "nested": { "deep": { "x": "bbb" } } }$$, 'strict $.**."x"'); It returns 2 matches: "aaa" and "bbb". However, what I'd like to get instead is 2 paths that point to the matches, i.e.,: - $.that[0] - $.nested.deep Can this be accomplished using means that are available out of the box? If not, what would be a sane way of implementing it? Thank you for your help, Alex --00000000000002ab8a05d3457911 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I am trying to figure out whether P= ostgres 14 allows me to find the paths to certain values in the JSON, rathe= r than the values themselves. To illustrate, here is a test query:

SELECT JSONB_PATH_QUERY($${
=C2=A0 "this": &q= uot;that",
=C2=A0 "that": [{"x": "aaa"= ;},{"y": "missed"}],
=C2=A0 "nested": {=C2=A0 =C2=A0 =C2=A0 =C2=A0 "deep": {
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 "x": "bbb"
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 }=
}$$, 'strict $.**."x"');

It returns 2 matches: "aaa" and "bbb". However, what I= 'd like to get instead is 2 paths that point to the matches, i.e.,:
- $.that[0]
- $.nested.deep

Can t= his be accomplished using means that are available out of the box? If not, = what would be a sane way of implementing it?


<= /div>
Thank you for your help,
Alex
--00000000000002ab8a05d3457911--