I need to update data in two elements of JSON array. The example below is simplified, usually it has more elements wit other keys
[{"key": "startDate", "value": "2022-02-05T23:00:00Z"}, {"key": "endDate", "value": "2022-02-05T23:00:00Z"}]
My goal is to change 'value' in startDate and endDate
My query is
UPDATE my_table ti
SET fields = jsonb_set(ti.fields, path, temp, false)
FROM my_table ti1,
LATERAL (
SELECT ARRAY [(ordinal - 1)::text, 'value'] AS path,
to_jsonb(((field ->> 'value')::timestamp with time zone at time zone 'CET')::date) AS temp
FROM jsonb_array_elements(ti1.fields #> '{}') WITH ORDINALITY arr(field, ordinal)
WHERE field ->> 'key' = 'startDate'
AND field ->> 'value' IS NOT NULL
) field
WHERE ti.id = ti1.id;
And the same query I do for endDate, just replacing WHERE condition.
So, I got two queries, but I want to replace it with one
I tried to rewrite WHERE condition to WHERE field ->> 'key' in ('startDate', 'endDate), but it didn't work and as a result I got only one (the first) key value updated
[{"key": "startDate", "value": "2022-02-06"}, {"key": "endDate", "value": "2022-02-05T23:00:00Z"}]
How can I update two values in one query?