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

From Tom Lane
Subject Re: Properly handling aggregate in nested function call
Date
Msg-id 559031.1639522278@sss.pgh.pa.us
Whole thread Raw
In response to Properly handling aggregate in nested function call  (Matt Magoffin <postgresql.org@msqr.us>)
Responses Re: Properly handling aggregate in nested function call  (Matt Magoffin <postgresql.org@msqr.us>)
Re: Properly handling aggregate in nested function call  (Matt Magoffin <postgresql.org@msqr.us>)
List pgsql-general
Matt Magoffin <postgresql.org@msqr.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



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Why can't I have a "language sql" anonymous block?
Next
From: "David G. Johnston"
Date:
Subject: Re: Why can't I have a "language sql" anonymous block?