Re: Properly handling aggregate in nested function call - Mailing list pgsql-general

From Matt Magoffin
Subject Re: Properly handling aggregate in nested function call
Date
Msg-id AF8238C6-E34C-452E-8718-D90BB5E231E2@msqr.us
Whole thread Raw
In response to Re: Properly handling aggregate in nested function call  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Properly handling aggregate in nested function call  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On 15/12/2021, at 11:51 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
You should
probably palloc temp arrays right here and then use construct_md_array
directly instead of dealing with an ArrayBuildState.

OK, I gave that a go [1] this time in a vec_agg_sum() aggregate, that operates much the same as the vec_agg_mean() one and is behaving in the same way. For example this shows the correct values:

SELECT vec_agg_sum(nums) FROM measurements;
NOTICE:  sum 0 = 4.92
NOTICE:  sum 1 = 5.91
NOTICE:  sum 2 = 14.80
    vec_agg_sum    
-------------------
 {4.92,5.91,14.80}
(1 row)


But adding unnest() goes back to seemingly memory address values:

SELECT unnest(vec_agg_sum(nums)) FROM measurements;
NOTICE:  sum 0 = 4.92
NOTICE:  sum 1 = 5.91
NOTICE:  sum 2 = 14.80
     unnest     
----------------
 94069010663032
 94069010663044
 94069010663056
(3 rows)

Any other ideas I could look into?

— m@


pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Best Strategy for Large Number of Images
Next
From: Bryn Llewellyn
Date:
Subject: Re: Why can't I have a "language sql" anonymous block?