Re: Properly handling aggregate in nested function call

From: Matt Magoffin <postgresql(dot)org(at)msqr(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Properly handling aggregate in nested function call
Date: 2021-12-15 22:54:33
Message-ID: AF8238C6-E34C-452E-8718-D90BB5E231E2@msqr.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 15/12/2021, at 11:51 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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@

[1] https://github.com/SolarNetwork/aggs_for_vecs/blob/df8b950c73d9b32fa6f016b44dd8859e9341fe0f/vec_agg_sum.c#L50-L52 <https://github.com/SolarNetwork/aggs_for_vecs/blob/df8b950c73d9b32fa6f016b44dd8859e9341fe0f/vec_agg_sum.c#L50-L52>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bryn Llewellyn 2021-12-15 23:18:57 Re: Why can't I have a "language sql" anonymous block?
Previous Message David G. Johnston 2021-12-15 22:51:48 Re: Best Strategy for Large Number of Images