I have a table in PostgreSQL. I want to perform element-wise addition for the arrays(i.e. col) after grouping them by time. The arrays are of varying dimensions. Example as follows:
| time  | col               |
|------ |------------------ |
| 1     | {1,2}             |
| 1     | {3,4,5,6}         |
| 2     | {}                |
| 2     | {7}               |
| 2     | {8,9,10}          |
| 3     | {11,12,13,14,15}  |
The result should be as follows:
| time  | col               |
|------ |------------------ |
| 1     | {4,6,5,6}         |
| 2     | {15,9,10}         |
| 3     | {11,12,13,14,15}  |
I found this answer which does something similar for fixed dimension of 3 elements. But it does not work for varying dimensions.
DBFiddle for example.