okbob / plpgsql_check

plpgsql_check is a linter tool (does source code static analyze) for the PostgreSQL language plpgsql (the native language for PostgreSQL store procedures).
https://groups.google.com/forum/#!forum/postgresql-extensions-hacking
Other
641 stars 53 forks source link

cache lookup failed for type 0 #137

Closed preethint closed 1 year ago

preethint commented 1 year ago

Found below observation when trigger function returns scaler variable instead of TRIGGER.

Please refer below example, where I am getting cache lookup failed error in RETURN error.

create table t1 (v1 int);

CREATE OR REPLACE FUNCTION public.test_fun()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
declare
v1 int:=10;
BEGIN
    update t1 set v1=10;
RETURN v1;
END;
$function$;

create or replace trigger trig1 
before update on t1
for each row
execute function test_fun();

plpgsql_check_db@115226=#select * from plpgsql_check_function('test_fun()', 't1');
               plpgsql_check_function                
-----------------------------------------------------
 error:XX000:6:RETURN:cache lookup failed for type 0
(1 row)

I think, here we should throw some meaningful error message.

okbob commented 1 year ago

Should be fixed by 1dd83a95a8f6394e9d53d6d7ef406927495770a0 commit

preethint commented 1 year ago

Thanks.

okbob commented 1 year ago

thank you for bug report