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/[email protected]

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

* Report specific SQLSTATEs for stats restore errors:
  https://postgr.es/m/[email protected]

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: 0001-Report-malformed-integer-aggregate-states-as-array-e.patch
Description: 0001-Report-malformed-integer-aggregate-states-as-array-e.patch

Reply via email to