Error when using array_agg with filter where clause in pg16 and pg17 - Mailing list pgsql-bugs

From Kaimeh
Subject Error when using array_agg with filter where clause in pg16 and pg17
Date
Msg-id CAK-+Jz9J=Q06-M7cDJoPNeYbz5EZDqkjQbJnmRyQyzkbRGsYkA@mail.gmail.com
Whole thread Raw
Responses Re: Error when using array_agg with filter where clause in pg16 and pg17
List pgsql-bugs
Hello!

In postgresql 16 and 17 using array_agg with filter where gives an error, while in postgres 15 exact same query works.

This is minimal sample for reproducing:

create table test (id int, data jsonb);

insert into test (id, data) values
(1, '{"a": null}'),
(2, '{"a": "2"}'),
(3, '{"a": "2"}'),
(4, '{"a": ""}');

select array_agg(distinct (data->>'a')::int) filter (where data->>'a' is not null and data->>'a' != '')
from test;

Last query in pg16 or pg17 returns ERROR #22P02 invalid input syntax for type integer: ""
In pg15 it returns correct result {2}

wbr, Ferossa.

pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #18883: Epoch issue
Next
From: PG Bug reporting form
Date:
Subject: BUG #18884: The CURRENT_TIMESTAMP value being returned in UTC-2.