Created
September 7, 2022 10:24
-
-
Save ker0x/55e78fbb1807070b06ce5b99bdb25194 to your computer and use it in GitHub Desktop.
Set a column value with an aggregate sum from a JSON column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH estimate_inter_durations AS ( | |
SELECT (json_array_elements(estimate_inter.sequences)->>'duration')::float AS duration, estimate_inter.id | |
FROM estimate_inter | |
INNER JOIN estimate ON estimate.id = estimate_inter.id | |
WHERE estimate.id = estimate_inter.id | |
) | |
UPDATE estimate | |
SET duration_value = ( | |
SELECT SUM(duration) | |
FROM estimate_inter_durations | |
WHERE estimate.id = estimate_inter_durations.id | |
GROUP BY estimate_inter_durations.id | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment