JSONpath query that returns paths to the matches

From: Alex R <ralienpp(at)gmail(dot)com>
To: pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: JSONpath query that returns paths to the matches
Date: 2021-12-16 15:56:48
Message-ID: CANK1NR1E1CyHcqF+xQvBYBY0+G4GGL_HKDDSad2am74zz_N3mg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message David G. Johnston 2021-12-16 16:08:36 Re: JSONpath query that returns paths to the matches
Previous Message Greg Rychlewski 2021-12-10 19:23:50 Streaming Replication Protocol and Logical Replication