0

Consider the following jsonb object:

{
 "track": {
 "segments": [
 {
 "location": [ 47.763, 13.4034 ],
 "startTime": "2018-10-14 10:05:14",
 "HR": 73
 },
 {
 "location": [ 47.706, 13.2635 ],
 "startTime": "2018-10-14 10:39:21",
 "HR": 135
 }
 ]
 }
}

I would like to query the object, to return only the following jsonb object, given the folloiwng paths:

  • track.segments.hr
{
 "track": {
 "segments": [
 {
 "HR": 73
 },
 {
 "HR": 135
 }
 ]
 }
}

How can i formulate the query, to retrieve this kind of data from the json, and still return the json object, with only the specified paths?

asked Mar 10, 2020 at 12:13

1 Answer 1

0

You almost certainly can't.

JSON doesn't [yet] have the equivalent of XML's XSLTransform, which could do what you describe, but [still] only after retrieving the entire blob of XML to work with.

Databases are really good at finding little bits of stuff and putting them together; they're far less good and taking large blobs of stuff and pulling them apart.

I assume what you're showing is a simplification but what you've shown could be done easily with ordinary, relational tables.

answered Mar 10, 2020 at 12:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.