RE: [PATCH] Report malformed integer aggregate states as array errors

From: "Strydom, Matthys" <strydom(at)amazon(dot)com>
To: "Burd, Greg" <gregburd(at)amazon(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: [PATCH] Report malformed integer aggregate states as array errors
Date: 2026-11-12 15:49:29
Message-ID: DS2PR18MB9275696404EDAB513A71510D13C9702@DS2PR18MB927569.namprd18.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

Several SQL-callable aggregate support functions accept an int8[]
transition state. They use elog(ERROR) when the supplied state does not
have the expected two-element shape. This means a direct call such as:

SELECT int8_avg(ARRAY[1]::int8[]);

reports SQLSTATE XX000.

The attached patch reports ERRCODE_ARRAY_SUBSCRIPT_ERROR (2202E)
instead. This matches existing array-shape checks, including the
array_agg state handling.

I found these related SQLSTATE cleanup discussions helpful:

* Improve error code and messages for some SQL-reachable code paths:
https://postgr.es/m/94ac928b-8370-4db5-ada5-579a9ebc089d@gmail.com

* Improve reporting of invalid weight symbols in setweight() et al.:
https://postgr.es/m/CAON2xHNaeLAUzRCXL5AmXLcXaSE_gWAVjWQRmLzc_oZ=1_Vf4Q@mail.gmail.com

* Report specific SQLSTATEs for stats restore errors:
https://postgr.es/m/19629-76babc04b683594d@postgresql.org

The patch changes all eight checks for this aggregate state
representation. It also adds a regression test for the direct
int8_avg() call.

I also noticed similar aggregate-state checks elsewhere, such as
check_float8_array() in float.c. I kept this patch focused on the
repeated int8[] checks. If this change is considered useful, I can
prepare a follow-up patch for the remaining cases.

Tested with:

make -C src/test/regress check-tests \
TESTS='test_setup create_index create_aggregate aggregates'

Regards,
Matthys Strydom
Amazon Web Services

Attachment Content-Type Size
0001-Report-malformed-integer-aggregate-states-as-array-e.patch application/octet-stream 5.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-11-12 15:54:35 Re: [PATCH] Report malformed integer aggregate states as array errors
Previous Message Tomas Vondra 2026-11-12 15:40:24 Re: reconsider_full_join_clause fails to consider if COALESCE() arguments are NULL-preserving