Let's say I have a table features which has a column data that contains json objects.
CREATE TABLE features ( id INTEGER PRIMARY KEY, data json )
Now, an example data object may be:
{"A":
{"B":
{"coordinates":[
{"x":1, "y":1},
{"x":10, "y":10}
]
}
}
Now I need to go through all the data in this data column and double the value of the coordinates.
I tried setting it to its own value divided by 0.5 but this seems to work for the first row and then sets all other rows to that exact same value.
update features
set data =
(select json_set(features.data, "$.A.B.coordinates[0].x", (select json_extract(features.data, "$.A.B.coordinates[0].x")/0.5 from features))
from features);
How do I reference its own value in json_set and keep repeating for each row? What is the best way to go through each row and double the coordinates?