Error from array_agg when table has many rows

From: Kirill Zdornyy <kirill(at)dineserve(dot)com>
To: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Error from array_agg when table has many rows
Date: 2025-03-07 20:07:45
Message-ID: atLI5Kce2ie1zcYjU0w_kjtVaxiYbYGTihrkLDmGZQnRDD4pnXukIATaABbnIj9pUnelC4ESvCXMm4HAyHg-v61XABaKpERj0A2IXzJZM7g=@dineserve.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,

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.

Please see the following SQL script for the minimum reproduction.

```
drop table if exists my_table;

create table my_table
(
my_text text
);

-- Insert a minimum of 200,000 rows.
do
$$
declare
counter integer := 0;
begin
while counter < 200000
loop
INSERT INTO my_table (my_text) VALUES ('A simple sentence.');
counter := counter + 1;
end loop;
end;
$$;

select array_agg(t)
from (select my_text from my_table WHERE my_text != '') t;
```

On my machine the issue appears if 200,000 or more rows exist. I used EXPLAIN and noticed that the query plan is different if this condition is met.

This is the query plan if fewer than 200,000 rows exist.

```
Aggregate (cost=1935.40..1935.41 rows=1 width=32)
-> Seq Scan on my_table (cost=0.00..1719.90 rows=86199 width=32)
Filter: (my_text <> ''::text)
```

This is the query plan if more than 200,000 rows exist.

```
Finalize Aggregate (cost=3801.65..3801.66 rows=1 width=32)
-> Gather (cost=3801.53..3801.64 rows=1 width=32)
Workers Planned: 1
-> Partial Aggregate (cost=2801.53..2801.54 rows=1 width=32)
-> Parallel Seq Scan on my_table (cost=0.00..2548.00 rows=101411 width=32)
Filter: (my_text <> ''::text)
```

I am also able to reproduce the issue on AWS RDS PostgreSQL 16.3.

Thank you!

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-03-07 20:08:20 Re: BUG #18835: spgist index fails to accept point with NaN
Previous Message PG Bug reporting form 2025-03-07 18:00:01 BUG #18835: spgist index fails to accept point with NaN