Re: [PG19] Bogus errors for polymorphic plpython functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PG19] Bogus errors for polymorphic plpython functions
Date: 2026-10-31 16:29:53
Message-ID: 233394.1793464193@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

shihao zhong <zhong950419(at)gmail(dot)com> writes:
> Did a quick test, I think it worked on master

> CREATE FUNCTION r3(OUT r record)
> AS $$ return (1, 2) $$ LANGUAGE plpython3u;
> SELECT * FROM r3() AS (a int, b int);
> SELECT * FROM r3();

Ah, good point. I was thinking about the general case,
which doesn't really work:

regression=# CREATE FUNCTION multiout_record(INOUT n integer, OUT record) AS $$
return (n, (n * 2, n * 3))
$$ LANGUAGE plpython3u;
CREATE FUNCTION
regression=# SELECT * FROM multiout_record(2);
ERROR: record type has not been registered
CONTEXT: while creating return value
PL/Python function "multiout_record"

But with just one "OUT record" parameter, that's equivalent to
"RETURNS record", so it should work. This is showing us another
omission in plpython's regression tests :-(

After sleeping on it, I've decided that while moving these checks into
the validator is a good idea, it's not the most appropriate way to fix
this in v19. That is, I now think that this is really funccache.c's
bug not plpython's: it should be on funccache.c to not fail in this
situation. Yesterday I'd been dithering over whether external users
of funccache.c might want the existing behavior, but I can't see how
it'd be useful to them. Validators subject to this issue would have
to construct fake fcinfos that are much more complete than what we've
expected so far.

So here's a v2 patch series. 0001 fixes the immediate problem by
teaching funccache.c to not fail, and I envision back-patching that
to v19 or maybe even v18. Then 0002 rearranges plpython's validator,
but I now think that should go to master only. It does cause a user-
visible behavioral change (tighter checking with check_function_bodies
off), and we should refrain from unnecessary changes of that kind
post-rc1.

regards, tom lane

Attachment Content-Type Size
v2-0001-Fix-failure-in-function-cache-entry-hashing-durin.patch text/x-diff 5.4 KB
v2-0002-Move-plpython-s-rejection-of-pseudotype-arguments.patch text/x-diff 11.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Lukas Fittl 2026-10-31 16:30:47 Re: Stack-based tracking of per-node WAL/buffer usage
Previous Message Srinath Reddy Sadipiralla 2026-10-31 16:24:34 Re: Call CalculateShmemSize() only once