I have a table:
create table public.config
(
id text not null,
payload json not null,
updated_at timestamp with time zone default now() not null
);
and the json field has the following structure:
{
"QuestsCommon":
[
{
"QuestType": "Standard",
"RotationQuestsList": []
},
{
"QuestType": "Daily", 👈️ need to remove elements from subarray ("RotationQuestsList") where "QuestType" == "Daily"
"RotationQuestsList":
[
{
"QuestId": "1", 👈️ need to remove array's element with "QuestId" == 1
"GroupId": "Reusable",
"Enabled": false
},
{
"QuestId": "2",
"GroupId": "Reusable",
"Enabled": false
}
]
},
{
"QuestType": "Weekly",
"RotationQuestsList": []
},
{
"QuestType": "Challenge",
"RotationQuestsList":
[
{
"QuestId": "Lucky",
"GroupId": "Regular",
"Enabled": true
}
]
}
]
}
I'd to write a query that removes object's from the subarray (RotationQuestsList ) of the QuestsCommon array by QuestType of the parent array and QuestId of the subarray (QuestId == 1, for example).
I found answers like Remove nested json object from array in postgres and How to remove object from json array?, but stuck anyway...