Thread: BUG #17057: Unexpected error: ERROR: unsupported target type: 0

BUG #17057: Unexpected error: ERROR: unsupported target type: 0

From
PG Bug reporting form
Date:
The following bug has been logged on the website:

Bug reference:      17057
Logged by:          Zlatoslav Petukhov
Email address:      zpetukhov@gmail.com
PostgreSQL version: 13.1
Operating system:   different linux versions
Description:

Hi to all,
I faced with an odd error while developing a stored procedure with
transaction control inside.
We use postgres v 13.1 on AWS RDS.
I maximally simplified the code to demonstrate the error.
The simplified code is here:
https://dbfiddle.uk/?rdbms=postgres_13&fiddle=8cff4a98ac7fcefaaf9f38db68240cc1
It fails when executed on postgres versions 11 and 13.1.
No error on v12 (at least in the dbfiddle.uk instance). I didn't tested on
13.2 - I don't have such instance.
The code is copied below (not sure about dbfiddle.uk rules, how long the
fiddle will be available, etc).
So.... The stored procedure:
-----------------------------
CREATE OR REPLACE PROCEDURE public.testp(
    INOUT p1 integer
)
LANGUAGE 'plpgsql'
AS $$
begin
  commit;

  if (p1 <= 10) then
    p1 := 7;
  else
    p1 := 77;
  end if;
  
end;
$$;
-----------------------------
And the calling code:
-----------------------------
--select version();
do
$$
declare 
  p1 integer;
begin
  p1 := -1;
  call testp(p1);
  RAISE NOTICE '! %', p1;

  p1 := -2;
  call testp(p1);
  RAISE NOTICE '! %', p1;

  p1 := 11;
  call testp(p1);
  RAISE NOTICE '! %', p1;
 
end;
$$
-----------------------------

Additional info:
the code raises the error only when executed for the first time in a
session.
the second (and subsequent) execution gives no errors.


Re: BUG #17057: Unexpected error: ERROR: unsupported target type: 0

From
Tom Lane
Date:
PG Bug reporting form <noreply@postgresql.org> writes:
> I faced with an odd error while developing a stored procedure with
> transaction control inside.

Hi, this works fine for me on all branches back to v11.
I get

NOTICE:  ! 7
NOTICE:  ! 7
NOTICE:  ! 77

which looks like the correct behavior.  I suspect you're hitting
the bug fixed in commit 0ea25ed10, so you need to update to 13.2
or later.

            regards, tom lane



Re: BUG #17057: Unexpected error: ERROR: unsupported target type: 0

From
Zlatoslav Petukhov
Date:
> I suspect you're hitting the bug fixed in commit 0ea25ed10,
> so you need to update to 13.2

Thank you for the answer.
Upgrading to 13.2 helped.
(this info is for other devs which will face the issue.
Google does not give much results on "ERROR: unsupported target type: 0"
so, probably, searching people will "land" here).