Issue with pg_get_functiondef

From: Edouard Tollet <edouard(dot)tollet(at)stoik(dot)io>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Issue with pg_get_functiondef
Date: 2023-12-12 09:33:27
Message-ID: CAMTFitQobPvh0_wbW_S-o7V03qcGkTWgZD-3ozXAbfzCcGuvgQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dear PostgreSQL developers,

I'm having trouble understanding the following, I apologize in advance if
it is not a bug.
The following query works and lists the functions name and definitions as
set in my database:

select * from (
select proname, prokind, pg_get_functiondef(oid) as def
from pg_proc
where pg_proc.prokind = 'f'
) def

however, if I add the filter where def is not null, it returns an error:
select * from (
select proname, prokind, pg_get_functiondef(oid) as def
from pg_proc
where pg_proc.prokind = 'f'
) def
where def is not null;
ERROR: "array_agg" is an aggregate function

(with VERBOSITY set to verbose I get:
ERREUR: 42809: « array_agg » est une fonction d'agrégat
EMPLACEMENT : pg_get_functiondef, ruleutils.c : 2926)

I understand that somehow the query above is calling pg_get_functiondef on
array_agg where I believe it shouldn't since array_agg has prokind set to a.
Filtering for pg_proc.prokind <> 'a' makes the query works again:
select * from (
select proname, prokind, pg_get_functiondef(oid) as def
from pg_proc
where pg_proc.prokind <> 'a'
) def
where def is not null;

I get an error if I write:
select * from (
select proname, prokind, pg_get_functiondef(oid) as def
from pg_proc
where pg_proc.prokind in ('f')
) def
where def is not null;
ERROR: "array_agg" is an aggregate function

but it works (and lists both functions and procedures) if I do:
select * from (
select proname, prokind, pg_get_functiondef(oid) as def
from pg_proc
where pg_proc.prokind in ('f', 'p')
) def
where def is not null;

I was able to reproduce these steps on a clean, up to date, Debian 12
install, without any data or user defined function.
SELECT version();
version

-------------------------------------------------------------------------------------------------------------------
PostgreSQL 15.5 (Debian 15.5-0+deb12u1) on x86_64-pc-linux-gnu, compiled
by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

Thanks in advance,
Best regards

--
Edouard Tollet
Data scientist | Stoïk

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Richard Guo 2023-12-12 09:50:27 Re: BUG #18238: Cross-partitition MERGE/UPDATE with delete-preventing trigger leads to incorrect memory access
Previous Message Michael Paquier 2023-12-12 09:03:43 Re: BUG #18240: Undefined behaviour in cash_mul_flt8() and friends