okbob/plpgsql_check

incorrect error with composite types and dropped columns

fvannee opened this issue · 3 comments

Thanks for maintaining plpgsql_check! I recently ran into a strange case that can be reproduced like this:

create type c1 as (
   a text
);
create table t1 (
   a c1,
   b c1
);
insert into t1 (values ('(abc)', '(def)'));
alter table t1 drop column a;

CREATE OR REPLACE FUNCTION public.test_function() RETURNS t1
    LANGUAGE plpgsql
    AS $$
DECLARE
myrow t1%ROWTYPE;
BEGIN
   SELECT * INTO myrow FROM t1 LIMIT 1;
   RETURN myrow;
END;
$$;

select * from test_function();
select * from plpgsql_check_function('public.test_function()');

Even though this is perfectly valid, plpgsql_check complains about the following:

error:42804:5:SQL statement:cannot cast composite value of "c1" type to a scalar value of "c1" type

The issue only occurs when there are dropped columns present. If you just create the table with one column from the scratch, then plpgsql_check does not complain.

okbob commented

should be fixed in 2.2.5 release, please check

thanks, that fixes it!

okbob commented

super :)

Thank you for bugreport