I have a table in Postgres 13 that looks something like:
Column | Type |
----------------
id bigint
ts_begin timestamp with time zone
ts_end timestamp with time zone
data jsonb not null '{}'::jsonb
Unfortunately the data is an array of key value pairs of with a UUID as the key and a timestamp as the value. E.g.
{"20220101234-deadbeef": "2021-11-18T09:09:09-05:00", "2022010234-cafefeed": "2021-11-18T08:08:08-05:00", ... }
My task to try and get the min and max values from that JSON object as update the ts_begin
and ts_end
values for each row.
Because the keys are not consistent, I think that the ->
or ->>
operators are not going to work for this task. Is that correct?
Is there a way to use json_each
or json_each_text
(or some other technique in SQL) to accomplish this task?