postgres.git / summary / log / commit / refs

commit    f291e3336d28f3f82ce0bb6503653ebe84ca7a50
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Mon Oct 26 18:03:24 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0

    Fix PL/pgSQL's handling of anycompatiblemultirange.
    
    When validating a PL/pgSQL function with polymorphic arguments or
    result type, we substitute a plausible concrete type for each
    polymorphic type.  anycompatiblemultirange was missed in both places
    that do this, when multiranges were added.  As a result, CREATE
    FUNCTION with an anycompatiblemultirange argument failed with
    "PL/pgSQL functions cannot accept type anycompatiblemultirange" when
    check_function_bodies is on.
    
    Also, a function returning anycompatiblemultirange was compiled by
    the validator with an int4 result type, and since the function cache
    key doesn't include the result type, a later call in the same session
    with int4range arguments reused that entry and failed trying to cast
    the multirange result to integer.
    
    Map anycompatiblemultirange to int4multirange, as is done for
    anymultirange, to fix both issues.
    
    Author: Jeevan Chalke <jeevan.chalke@enterprisedb.com>
    Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
    Discussion: https://postgr.es/m/CAM2+6=VEXCo7tPaxX+9_zN8SJ9DiPp2NTj_sPGN+Tb0wWTBp=w@mail.gmail.com
    Backpatch-through: 14


src/pl/plpgsql/src/pl_comp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c index 84a119a08e9..1dbbeb3a30a 100644 --- a/src/pl/plpgsql/src/pl_comp.c +++ b/src/pl/plpgsql/src/pl_comp.c @@ -515,7 +515,8 @@ do_compile(FunctionCallInfo fcinfo, else if (rettypeid == ANYRANGEOID || rettypeid == ANYCOMPATIBLERANGEOID) rettypeid = INT4RANGEOID; - else if (rettypeid == ANYMULTIRANGEOID) + else if (rettypeid == ANYMULTIRANGEOID || + rettypeid == ANYCOMPATIBLEMULTIRANGEOID) rettypeid = INT4MULTIRANGEOID; else /* ANYELEMENT or ANYNONARRAY or ANYCOMPATIBLE */ rettypeid = INT4OID; @@ -2590,6 +2591,7 @@ plpgsql_resolve_polymorphic_argtypes(int numargs, argtypes[i] = INT4RANGEOID; break; case ANYMULTIRANGEOID: + case ANYCOMPATIBLEMULTIRANGEOID: argtypes[i] = INT4MULTIRANGEOID; break; default: [parent: 3651d7c58bc1]