Re: BUG #18443: jsonb_agg issue. Again. - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #18443: jsonb_agg issue. Again.
Date
Msg-id CAKFQuwY4SWR6WqUp5DwauLMumJhr71+FFcY-qMFLFMqfq+fCzg@mail.gmail.com
Whole thread Raw
In response to BUG #18443: jsonb_agg issue. Again.  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18443: jsonb_agg issue. Again.
List pgsql-bugs
On Fri, Apr 19, 2024 at 8:25 AM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      18443
Logged by:          Alexander Tsaregorodtsev
Email address:      pfunk@mail.ru
PostgreSQL version: 12.18
Operating system:   Official docker container
Description:       

Greetings!
Is it expected behavior?


--simple function raising ONE notice and returning record of 2 int`s
drop function if exists public.out2(jsonb);
create or replace function public.out2(_in jsonb, a out int, b out int)
returns record
as
$body$
begin
        raise notice '***';
end;
$body$
  language plpgsql;

--similar function raising notice but returning record of 3 int`s 
drop function if exists public.out3();
create or replace function public.out3(_in jsonb, a out int, b out int, c
out int)
returns record

--Problem! function out2 has invoked 2 times (two NOTICE`s and accidentally
number of output parameters)
select (public.out2(jsonb_agg(jsonb_build_object('col', col)))).* --,
jsonb_agg(jsonb_build_object('col', col))
from tmp_view;


You wrote a table-producing function (one row but three columns).  Those need [1] to be executed in the FROM clause, via an implicit or explicit LATERAL join if you have data from other relations being fed in as input arguments.

David J.

1. well, at least if you don't want to see this kind of artifact where the way to expand .* is to copy the expression preceding it.

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18443: jsonb_agg issue. Again.
Next
From: Ц
Date:
Subject: Re: BUG #18443: jsonb_agg issue. Again.