Sample Header Ad - 728x90

postgresql function to automatically merge and add two jsonb values from different tables when one is updated and store it in a third

0 votes
1 answer
689 views
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
Asked by user1898662 (11 rep)
Mar 17, 2021, 12:05 AM
Last activity: Jan 24, 2025, 12:01 PM