Re: ERROR: type of parameter 1 (fruit2) does not match that when preparing the plan (fruit1)

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: d <dchuck(at)yurfish(dot)com>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: ERROR: type of parameter 1 (fruit2) does not match that when preparing the plan (fruit1)
Date: 2022-05-01 15:58:38
Message-ID: CAKFQuwaZR0F4FL0RoP2sQ2y9v3V5GCZh9UofUmeS9BFPtsgp=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Sun, May 1, 2022 at 8:44 AM d <dchuck(at)yurfish(dot)com> wrote:

> -------to reproduce --------------------------------------
> CREATE OR REPLACE FUNCTION record_to_form_data(p_r record)
> RETURNS text
> LANGUAGE plpgsql
> AS $function$
> begin
> return (
> select string_agg(format('%s=%s',key,urlencode(value)),'&')
> from
> (select p_r.*) i,
> hstore(i.*) as h,each(h) );
> end;
> $function$;
>

Not a bug, it is a documented limitation.

It is your use of "(select p_r.*)" that is problematic.

https://www.postgresql.org/docs/current/plpgsql-implementation.html#PLPGSQL-PLAN-CACHING

"""
The mutable nature of record variables presents another problem in this
connection. When fields of a record variable are used in expressions or
statements, the data types of the fields must not change from one call of
the function to the next, since each expression will be analyzed using the
data type that is present when the expression is first reached. EXECUTE can
be used to get around this problem when necessary.
"""

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2022-05-01 17:08:57 Re: ERROR: type of parameter 1 (fruit2) does not match that when preparing the plan (fruit1)
Previous Message d 2022-04-30 23:23:19 ERROR: type of parameter 1 (fruit2) does not match that when preparing the plan (fruit1)

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2022-05-01 16:52:09 Re: testclient.exe installed under MSVC
Previous Message Magnus Hagander 2022-05-01 15:53:16 Re: Accessing git.postgresql.org fails