Re: Error from array_agg when table has many rows

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: Kirill Zdornyy <kirill@dineserve.com>
Cc: "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2025-03-08T09:38:51Z
Lists: pgsql-bugs
On Sat, Mar 8, 2025 at 8:10 AM Kirill Zdornyy <kirill@dineserve.com> wrote:
> After upgrading from PostgreSQL 12.19 to PostgreSQL 16.3 the function "array_agg" gives me the following error under certain conditions.
>
> ERROR: input of anonymous composite types is not implemented
>
> I was also able reproduce the issue on PostgreSQL 17.4 via the latest currently available Docker image.

Thanks for the report!  I can reproduce it on master with the query
below.

create table t (a int);
insert into t values (1);

set parallel_setup_cost=0;
set parallel_tuple_cost=0;
set min_parallel_table_scan_size=0;

# select array_agg(s) from (select * from t) s;
ERROR:  input of anonymous composite types is not implemented

And the plan for this query is:

explain (verbose, costs off)
select array_agg(s) from (select * from t) s;
                    QUERY PLAN
---------------------------------------------------
 Finalize Aggregate
   Output: array_agg(ROW(t.a))
   ->  Gather
         Output: (PARTIAL array_agg(ROW(t.a)))
         Workers Planned: 2
         ->  Partial Aggregate
               Output: PARTIAL array_agg(ROW(t.a))
               ->  Parallel Seq Scan on public.t
                     Output: t.a
(9 rows)

We are performing deserialization during the final phase of the
aggregation on data of type RECORD but we fail to provide a valid
typmod (array_agg_deserialize() uses -1 as the typmod when calling the
receiveproc).

I haven't verified it, but I suspect it's related to 16fd03e95.

Thanks
Richard



Commits

  1. Don't try to parallelize array_agg() on an anonymous record type.