Lets say that tableA has column columnA with jsonb data in it like the following:
{
"A": 5,
"B": 15,
"C": 20
}
and tableB has columnA with jsonb data in it like the following:
{
"B": 10,
"C": 55,
"D": 60
}
Is it possible to set it up so that whenever either of the jsonb columns from tableA or tableB change then both jsonB columns will be taken, merged and added to a third table, tableC?
so in this example, if the column in tableB was modified, then what gets stored in tableC will be:
{
"A": 5,
"B": 25,
"C": 75,
"D": 60
}
The keys and values are retrieved from separate APIs and are unknown ahead of time. I'd like to keep them separate but also have a table that summarizes all the overall values.
Currently using postgresql 12.5 but can move to 13.1 if necessary
thanks in advance
Best Answer
Check out this PostgreSQL function
Call it like
to get
apart from a lot of comments.
Using HSTORE for intermediate results: