Re: Error from array_agg when table has many rows

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Kirill Zdornyy <kirill(at)dineserve(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Error from array_agg when table has many rows
Date: 2025-03-08 09:38:51
Message-ID: CAMbWs49WUftz6gXGPSVrZJ0czZ1RCtQz4RxDZKEKZtYADvA6Sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sat, Mar 8, 2025 at 8:10 AM Kirill Zdornyy <kirill(at)dineserve(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-03-08 15:50:01 Re: Error from array_agg when table has many rows
Previous Message Bertrand Drouvot 2025-03-08 08:02:35 Re: BUG #18828: Crash when pg_get_logical_snapshot_meta() passed empty string