Re: Properly handling aggregate in nested function call

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

Matt Magoffin <postgresql(dot)org(at)msqr(dot)us> writes:
> Any ideas what I’m doing wrong here? The source is available here:

> https://github.com/SolarNetwork/aggs_for_vecs/blob/9e742cdc32a113268fd3c1f928c8ac724acec9f5/vec_agg_mean.c

Hmm, I think you're abusing the ArrayBuildState API. In particular,
what guarantees that the astate->dvalues and astate->dnulls arrays
are long enough for what you're stuffing into them? You should
probably palloc temp arrays right here and then use construct_md_array
directly instead of dealing with an ArrayBuildState.

Also, I wonder what happens when state->vec_counts[i] is zero.
That's seemingly not your problem right now, since the ereport(NOTICE)
is being reached; but it sure looks like trouble waiting to happen.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-12-14 22:58:49 Re: Why can't I have a "language sql" anonymous block?
Previous Message Adrian Klaver 2021-12-14 20:47:09 Re: Why can't I have a "language sql" anonymous block?