Initial array in function to aggregate multi-dimensional array

后端 未结 2 563
庸人自扰
庸人自扰 2020-12-03 06:15

I have a table with arrays of integer.

I want to create an aggregate function that will return a 2-dimensional array with all the rows together. It then gets passed

2条回答
  •  长情又很酷
    2020-12-03 06:55

    Using the built-in array_cat function works.

    CREATE AGGREGATE array_sum2 (int[])  (
        SFUNC     = array_cat,
        STYPE     = int[],
        INITCOND  = '{}'
    );
    

    test:

    select array_sum2(array[d.a]) from (select array[1,1,2,3] as a union select array[5,8,13,21] as a) d;
           array_sum2        
    -------------------------
     {{1,1,2,3},{5,8,13,21}}
    

提交回复
热议问题