Re: BUG #18463: Possible bug in stored procedures with polymorphic OUT parameters

Поиск
Список
Период
Сортировка
От Dmitry Dolgov
Тема Re: BUG #18463: Possible bug in stored procedures with polymorphic OUT parameters
Дата
Msg-id 20240514151843.yvq3wlt7n2kechv5@ddolgov.remote.csb
обсуждение исходный текст
Ответ на BUG #18463: Possible bug in stored procedures with polymorphic OUT parameters  (PG Bug reporting form <noreply@postgresql.org>)
Ответы Re: BUG #18463: Possible bug in stored procedures with polymorphic OUT parameters  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
> On Tue, May 14, 2024 at 06:45:29AM +0000, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference:      18463
> Logged by:          Drew Kimball
> Email address:      drewk@cockroachlabs.com
> PostgreSQL version: 16.3
> Operating system:   macOS
> Description:
>
> Hello,
>
> I believe there may be a bug related to stored procedures with
> polymorphic-typed OUT parameters:
>
> CREATE PROCEDURE p(INOUT x ANYELEMENT) LANGUAGE SQL AS $$ SELECT x; $$;
> CALL p(1);
>
> The above example results in an error message "cannot display a value of
> type anyelement", but I would expect it to succeed and output "1". This also
> reproduces with the following stored procedures:
>
> CREATE PROCEDURE p(INOUT x ANYELEMENT) LANGUAGE SQL AS $$ SELECT 1; $$;
> CREATE PROCEDURE p(x ANYELEMENT, OUT y ANYELEMENT) LANGUAGE SQL AS $$ SELECT
> x; $$;
> CREATE PROCEDURE p(x ANYARRAY, OUT y ANYELEMENT) LANGUAGE SQL AS $$ SELECT
> x[1]; $$;
>
> Interestingly, this doesn't seem to reproduce when the OUT param has type
> ANYARRAY. The following example succeeds:
>
> CREATE PROCEDURE p(INOUT x ANYARRAY) LANGUAGE SQL AS $$ SELECT x; $$;
> CALL p(ARRAY[1, 2, 3]);

After looking at this I've got an impression this type of procedures
have to be disallowed in interpret_function_parameter_list. What happens
is that the procedure is created with INOUT anyelement argument and
return type record, because "procedures with output parameters always
return RECORD". I guess this contradicts the way how anyelement has to
be resolved, leading to this behaviour.

At the same time if we try to a function of the same type (INOUT
anyelement argument and returning record), we will get an error right
away:

    ERROR:  42P13: function result type must be anyelement because of
    OUT parameters

This is I think the behaviour that has to be enforced for procedures as
well. It works for anyarray only because of a side effect that
anyarray_out is allowed, due to some columns in pg_statistic having this
type.



В списке pgsql-bugs по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: BUG #18362: unaccent rules and Old Greek text
Следующее
От: PG Bug reporting form
Дата:
Сообщение: BUG #18464: Replacing a SQL function silently drops the generated columns that use this function