From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | mjurca(at)centrum(dot)cz |
Subject: | BUG #17610: Use of multiple composite types incompatible with record-typed function parameter |
Date: | 2022-09-08 10:19:30 |
Message-ID: | 17610-fb1eef75bf6c2364@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 17610
Logged by: Martin Jurča
Email address: mjurca(at)centrum(dot)cz
PostgreSQL version: 14.5
Operating system: Linux, Debian 10.2.1-6, x86
Description:
The SQL code at the end of this bug report ends with the following error:
2022-09-08 10:09:02.173 GMT [174] ERROR: type of parameter 1
(composite_type_2) does not match that when preparing the plan
(composite_type_1)
2022-09-08 10:09:02.173 GMT [174] CONTEXT: PL/pgSQL function
polymorphic_fuction(record) line 6 at EXECUTE
2022-09-08 10:09:02.173 GMT [174] STATEMENT: SELECT * FROM
polymorphic_fuction(
CAST(ROW(2) AS composite_type_2)
);
ERROR: 42804: type of parameter 1 (composite_type_2) does not match that
when preparing the plan (composite_type_1)
CONTEXT: PL/pgSQL function polymorphic_fuction(record) line 6 at EXECUTE
LOCATION: plpgsql_param_eval_generic_ro, pl_exec.c:6648
The expected output is:
polymorphic_fuction
---------------------
2
(1 row)
If I understand the documentation
(https://www.postgresql.org/docs/current/plpgsql-implementation.html#PLPGSQL-PLAN-CACHING)
correctly, this should work. I noticed that the record type is not listed
among polymorphic types
(https://www.postgresql.org/docs/current/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC)
but PL/pgSQL documentation
(https://www.postgresql.org/docs/current/plpgsql-overview.html#PLPGSQL-ARGS-RESULTS)
states that any composite type can be passed to a record parameter.
Full version info:
PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6)
10.2.1 20210110, 64-bit
I am not sure if this is an error on my part, at the PostgreSQL server, or
in the documentation, but any help or clarification would be appreciated.
SQL code producing the error:
CREATE TYPE composite_type_1 AS (
num int
);
CREATE TYPE composite_type_2 AS (
num int
);
CREATE FUNCTION polymorphic_fuction(
arg record
)
RETURNS int
LANGUAGE plpgsql
AS $$
DECLARE
result_num int;
BEGIN
-- Using either SELECT or EXECUTE has the same outcome (this I
understand).
EXECUTE 'SELECT ($1).num'
INTO STRICT result_num
USING arg;
RETURN result_num;
END;
$$;
SELECT * FROM polymorphic_fuction(
CAST(ROW(1) AS composite_type_1)
);
SELECT * FROM polymorphic_fuction(
CAST(ROW(2) AS composite_type_2)
);
From | Date | Subject | |
---|---|---|---|
Next Message | Ming | 2022-09-08 10:45:15 | Re: Postgres offset and limit bug |
Previous Message | David Rowley | 2022-09-08 09:03:33 | Re: Postgres offset and limit bug |