pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: mjurca@centrum.cz
Subject: BUG #17610: Use of multiple composite types incompatible with record-typed function parameter
Date: Thu, 08 Sep 2022 10:19:30 +0000
Message-ID: <17610-fb1eef75bf6c2364@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17610
Logged by:          Martin JurĨa
Email address:      mjurca@centrum.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)
);



view thread (6+ messages)  latest in thread

Message-ID: <17610-fb1eef75bf6c2364@postgresql.org>
Permalink:  ../17610-fb1eef75bf6c2364@postgresql.org/
Also on:    postgresql.org/message-id/17610-fb1eef75bf6c2364@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, mjurca@centrum.cz
  Subject: Re: BUG #17610: Use of multiple composite types incompatible with record-typed function parameter
  In-Reply-To: <17610-fb1eef75bf6c2364@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox