I need to update jsonb column by jsonb_set, to use jsonb_set, need a full Json Path. How could I get full jsonb path when jsonb has list?
For example, I got a JSON :
{
"Laptop": {
"brand": "Dell",
"price": 1200,
"specs": [
{
"name": "CPU",
"Brand": "Intel"
},
{
"name": "GPU",
"Brand": "Nvdia"
},
{
"name": "RAM",
"Brand": "Kingston"
}
]
}
}
I need some query like
SELECT <full_path>
FROM table
WHERE jsonb_path_query_first(col,"$.Laptop.specs[*].name")::text='"CPU"'`;
I need a full path that matches the query above
the return could be
$.Laptop.specs[0].name
or even better {Laptop,specs,0,name}
Is there any way to achieve this in Postgres?
2
Answers
In my case, for anyone facing the same problem, my current solution would be
Based on my understanding you need the index of the path? let me know
Output