@@ -8199,3 +8199,77 @@ select * from plpgsql_check_function('test_function');
81998199------------------------
82008200(0 rows)
82018201
8202+ drop function test_function();
8203+ load 'plpgsql_check';
8204+ drop type testtype cascade;
8205+ create type testtype as (a int, b int);
8206+ create function test_function()
8207+ returns record as $$
8208+ declare r record;
8209+ begin
8210+ r := (10,20);
8211+ if false then
8212+ return r;
8213+ end if;
8214+
8215+ return null;
8216+ end;
8217+ $$ language plpgsql;
8218+ create function test_function33()
8219+ returns record as $$
8220+ declare r testtype;
8221+ begin
8222+ r := (10,20);
8223+ if false then
8224+ return r;
8225+ end if;
8226+
8227+ return null;
8228+ end;
8229+ $$ language plpgsql;
8230+ -- should not to raise false alarm due check against fake result type
8231+ select plpgsql_check_function('test_function');
8232+ plpgsql_check_function
8233+ ------------------------
8234+ (0 rows)
8235+
8236+ select plpgsql_check_function('test_function33');
8237+ plpgsql_check_function
8238+ ------------------------
8239+ (0 rows)
8240+
8241+ -- try to check in passive mode
8242+ set plpgsql_check.mode = 'every_start';
8243+ select test_function();
8244+ test_function
8245+ ---------------
8246+
8247+ (1 row)
8248+
8249+ select test_function33();
8250+ test_function33
8251+ -----------------
8252+
8253+ (1 row)
8254+
8255+ select * from test_function() as (a int, b int);
8256+ a | b
8257+ ---+---
8258+ |
8259+ (1 row)
8260+
8261+ select * from test_function33() as (a int, b int);
8262+ a | b
8263+ ---+---
8264+ |
8265+ (1 row)
8266+
8267+ -- should to identify error
8268+ select * from test_function() as (a int, b int, c int);
8269+ ERROR: returned record type does not match expected record type
8270+ select * from test_function33() as (a int, b int, c int);
8271+ ERROR: returned record type does not match expected record type
8272+ drop function test_function();
8273+ drop function test_function33();
8274+ drop type testtype;
8275+ set plpgsql_check.mode = 'disabled';
0 commit comments