I have a table A
, where data
is a json column, and timestamp
is a timestamp with timezone column:
timestamp | data |
---|---|
2023-08-29 13:00:00-04 | { "a_123":{ "temp":85, "uv":5, "rain":0 }, "b_123":{ "temp":85, "uv":5, "rain":0 } } |
2023-08-29 14:00:00-04 | { "a_123":{ "temp":70, "uv" 1:, 1"rain":5 }, "b_123":{ "temp":73, "uv":1, "rain":7 } } |
2023-08-29 15:00:00-04 | { "a_123":{ "temp":83, "uv":4, "rain":1 }, "b_123":{ "temp":87, "uv":7, "rain":0 } } |
I have a second table B
:
id | location | elevation | tag |
---|---|---|---|
a_123 | 04662 | 155m | blue |
b_123 | 84003 | 15m | yellow |
I can map individual data column keys eg. a_123
from table A
onto the matching id
from table B
but in my case the data column keys from table A
are dynamic.
How would I produce a table where the nested timestamp data is mapped to each id
as follows, from the sample data provided above? Thanks for any help/docs.
id | location | elevation | tag | data |
---|---|---|---|---|
a_123 | 04662 | 155m | blue | { "2023-08-29 13:00:00-04":{ "temp":85, "uv":5, "rain":0 }, "2023-08-29 14:00:00-04":{ "temp":70, "uv":1, "rain":5 }, "2023-08-29 15:00:00-04":{ "temp":83, "uv":4, "rain":1 } } |
b123 | 84003 | 15m | yellow | { "2023-08-29 13:00:00-04":{ "temp":85, "uv":5, "rain":0 }, "2023-08-29 14:00:00-04":{ "temp":73, "uv":1, "rain":7 }, "2023-08-29 15:00:00-04":{ "temp":87, "uv":7, "rain":0 } } |