I searched a lot to find solution and I found something similar but unfortunately I couldn't apply it to my case, maybe because I am yet new to Postgres. The link to this similar issue is here: Update a JSON column with WHERE Clause in JSON Column Postgres
I would like to update a specific data inside Postgres/ JSON.
{
"name": "wewgrg",
"path": "fitnessappmaven\\src\\main\\java\\com\\klaro\\fitnessappmaven\\tempWorkoutIcons\\yoga.png",
"type": "Gym"
},
{
"name": "rhhrh",
"path": "fitnessappmaven\\src\\main\\java\\com\\klaro\\fitnessappmaven\\tempWorkoutIcons\\yoga.png",
"type": "Cardio"
},
This is the JSON structure I would like to modify. The name indicates the name of the workout. What I'd like to do is to update "name" where "name" is "wewgrg" and where the "username" column is Jon Doe(for example).
I tried something like this, but obviously the second where clause doesn't work.
UPDATE my_users SET json_workouts = JSONB_SET(json_workouts,'{name}','\"LOL\"') WHERE username='c' AND '{name}' = 'wewgrg';
So as far as I know this query works until the first WHERE clause and I don't know how to specify it further by the "name" property itself.
I hope I wrote it understandable. Thank you for any help in advance!
P.S.: I got answer previously regarding to storing/updating JOSN data in Postgres, that it would be easier to use properly normalized data. I have no idea what is that, if you suggest it, please provide example! Thank you :)