Skip to content

Commit 43bfbe5

Browse files
committed
fix regress tests and preparing for pg18
1 parent 8e497fa commit 43bfbe5

8 files changed

+550
-30
lines changed

expected/plpgsql_check_active-18.out

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
LOAD 'plpgsql';
2+
CREATE EXTENSION IF NOT EXISTS plpgsql_check;
3+
NOTICE: extension "plpgsql_check" already exists, skipping
4+
set client_min_messages to notice;
5+
create or replace function fxtest()
6+
returns void as $$
7+
declare
8+
v_sqlstate text;
9+
v_message text;
10+
v_context text;
11+
begin
12+
get stacked diagnostics
13+
v_sqlstate = returned_sqlstate,
14+
v_message = message_text,
15+
v_context = pg_exception_context;
16+
end;
17+
$$ language plpgsql;
18+
select * from plpgsql_check_function('fxtest');
19+
plpgsql_check_function
20+
-----------------------------------------------------------------------------------------------------------
21+
error:0Z002:7:GET STACKED DIAGNOSTICS:GET STACKED DIAGNOSTICS cannot be used outside an exception handler
22+
(1 row)
23+
24+
drop function fxtest();
25+
create or replace procedure prtest()
26+
as $$
27+
begin
28+
commit;
29+
end;
30+
$$ language plpgsql;
31+
select * from plpgsql_check_function('prtest'); --ok
32+
plpgsql_check_function
33+
------------------------
34+
(0 rows)
35+
36+
create or replace procedure prtest()
37+
as $$
38+
begin
39+
begin
40+
begin
41+
commit;
42+
end;
43+
end;
44+
exception when others then
45+
raise;
46+
end;
47+
$$ language plpgsql;
48+
select * from plpgsql_check_function('prtest'); --error
49+
plpgsql_check_function
50+
---------------------------------------------------------------------
51+
error:2D000:5:COMMIT:cannot commit while a subtransaction is active
52+
(1 row)
53+
54+
create or replace procedure prtest()
55+
as $$
56+
begin
57+
raise exception 'error';
58+
exception when others then
59+
begin
60+
begin
61+
commit;
62+
end;
63+
end;
64+
end;
65+
$$ language plpgsql;
66+
select * from plpgsql_check_function('prtest'); --ok
67+
plpgsql_check_function
68+
------------------------
69+
(0 rows)
70+
71+
drop procedure prtest();
72+
create function return_constant_refcursor() returns refcursor as $$
73+
declare
74+
rc constant refcursor;
75+
begin
76+
open rc for select a from rc_test;
77+
return rc;
78+
end
79+
$$ language plpgsql;
80+
create table rc_test(a int);
81+
select * from plpgsql_check_function('return_constant_refcursor');
82+
plpgsql_check_function
83+
-------------------------------------------------------
84+
error:22005:5:OPEN:variable "rc" is declared CONSTANT
85+
(1 row)
86+
87+
drop table rc_test;
88+
drop function return_constant_refcursor();
89+
create procedure p1(a int, out b int)
90+
as $$
91+
begin
92+
b := a + 10;
93+
end;
94+
$$ language plpgsql;
95+
create function f1()
96+
returns void as $$
97+
declare b constant int;
98+
begin
99+
call p1(10, b);
100+
end;
101+
$$ language plpgsql;
102+
select * from plpgsql_check_function('f1');
103+
plpgsql_check_function
104+
------------------------------------------------------
105+
error:22005:4:CALL:variable "b" is declared CONSTANT
106+
(1 row)
107+
108+
drop function f1();
109+
drop procedure p1(int, int);
110+
create or replace function f1()
111+
returns int as $$
112+
declare c constant int default 100;
113+
begin
114+
return c;
115+
end;
116+
$$ language plpgsql;
117+
-- should be ok
118+
select * from plpgsql_check_function('f1');
119+
plpgsql_check_function
120+
------------------------
121+
(0 rows)
122+
123+
drop function f1();
124+
-- do not raise false warning
125+
create or replace function test_function()
126+
returns text as $$
127+
declare s text;
128+
begin
129+
get diagnostics s = PG_CONTEXT;
130+
return s;
131+
end;
132+
$$ language plpgsql;
133+
create or replace procedure test_procedure()
134+
as $$
135+
begin
136+
null;
137+
end;
138+
$$ language plpgsql;
139+
-- should be without any warnings
140+
select * from plpgsql_check_function('test_function', performance_warnings=>true);
141+
plpgsql_check_function
142+
------------------------
143+
(0 rows)
144+
145+
select * from plpgsql_check_function('test_procedure', performance_warnings=>true);
146+
plpgsql_check_function
147+
------------------------
148+
(0 rows)
149+
150+
drop function test_function();
151+
drop procedure test_procedure();
152+
-- detect dependecy in CALL statement
153+
create or replace function fx1_dep(int)
154+
returns int as $$
155+
begin
156+
return $1;
157+
end;
158+
$$ language plpgsql;
159+
create or replace procedure px1_dep(int)
160+
as $$
161+
begin
162+
end;
163+
$$ language plpgsql;
164+
create or replace function test_function()
165+
returns void as $$
166+
begin
167+
call px1_dep(fx1_dep(10));
168+
end;
169+
$$ language plpgsql;
170+
select type, schema, name, params from plpgsql_show_dependency_tb('test_function');
171+
type | schema | name | params
172+
-----------+--------+---------+-----------
173+
FUNCTION | public | fx1_dep | (integer)
174+
PROCEDURE | public | px1_dep | (integer)
175+
(2 rows)
176+
177+
drop function test_function();
178+
drop procedure px1_dep(int);
179+
drop function fx1_dep(int);

expected/plpgsql_check_active.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,8 +2441,8 @@ $$ language plpgsql;
24412441
select * from plpgsql_check_function('tx(int)');
24422442
plpgsql_check_function
24432443
-------------------------------------------------------------------------------------------
2444-
warning:00000:3:statement block:parameter "a" is overlapped
2445-
Detail: Local variable overlap function parameter.
2444+
warning:00000:3:statement block:parameter "a" is shadowed
2445+
Detail: Local variable shadows function parameter.
24462446
warning extra:00000:5:statement block:variable "ax" shadows a previously defined variable
24472447
Hint: SET plpgsql.extra_warnings TO 'shadowed_variables'
24482448
warning:00000:2:DECLARE:unused variable "ax"
@@ -8965,14 +8965,14 @@ begin
89658965
end;
89668966
$$ language plpgsql immutable;
89678967
select * from plpgsql_check_function('fx1');
8968-
plpgsql_check_function
8969-
----------------------------------------------------------------------------
8970-
warning:00000:2:statement block:parameter "found" is overlapped
8971-
Detail: Local auto variable overlap function parameter.
8972-
warning:00000:3:FOR with integer loop variable:parameter "i" is overlapped
8973-
Detail: Local auto variable overlap function parameter.
8974-
warning:00000:5:FOR with integer loop variable:parameter "j" is overlapped
8975-
Detail: Local auto variable overlap function parameter.
8968+
plpgsql_check_function
8969+
--------------------------------------------------------------------------
8970+
warning:00000:2:statement block:parameter "found" is shadowed
8971+
Detail: Local auto variable shadows function parameter.
8972+
warning:00000:3:FOR with integer loop variable:parameter "i" is shadowed
8973+
Detail: Local auto variable shadows function parameter.
8974+
warning:00000:5:FOR with integer loop variable:parameter "j" is shadowed
8975+
Detail: Local auto variable shadows function parameter.
89768976
warning extra:00000:unmodified OUT variable "i"
89778977
warning extra:00000:unmodified OUT variable "j"
89788978
warning extra:00000:unmodified OUT variable "found"

expected/plpgsql_check_active_1.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,8 +2441,8 @@ $$ language plpgsql;
24412441
select * from plpgsql_check_function('tx(int)');
24422442
plpgsql_check_function
24432443
-------------------------------------------------------------------------------------------
2444-
warning:00000:3:statement block:parameter "a" is overlapped
2445-
Detail: Local variable overlap function parameter.
2444+
warning:00000:3:statement block:parameter "a" is shadowed
2445+
Detail: Local variable shadows function parameter.
24462446
warning extra:00000:5:statement block:variable "ax" shadows a previously defined variable
24472447
Hint: SET plpgsql.extra_warnings TO 'shadowed_variables'
24482448
warning:00000:2:DECLARE:unused variable "ax"
@@ -8967,14 +8967,14 @@ begin
89678967
end;
89688968
$$ language plpgsql immutable;
89698969
select * from plpgsql_check_function('fx1');
8970-
plpgsql_check_function
8971-
----------------------------------------------------------------------------
8972-
warning:00000:2:statement block:parameter "found" is overlapped
8973-
Detail: Local auto variable overlap function parameter.
8974-
warning:00000:3:FOR with integer loop variable:parameter "i" is overlapped
8975-
Detail: Local auto variable overlap function parameter.
8976-
warning:00000:5:FOR with integer loop variable:parameter "j" is overlapped
8977-
Detail: Local auto variable overlap function parameter.
8970+
plpgsql_check_function
8971+
--------------------------------------------------------------------------
8972+
warning:00000:2:statement block:parameter "found" is shadowed
8973+
Detail: Local auto variable shadows function parameter.
8974+
warning:00000:3:FOR with integer loop variable:parameter "i" is shadowed
8975+
Detail: Local auto variable shadows function parameter.
8976+
warning:00000:5:FOR with integer loop variable:parameter "j" is shadowed
8977+
Detail: Local auto variable shadows function parameter.
89788978
warning extra:00000:unmodified OUT variable "i"
89798979
warning extra:00000:unmodified OUT variable "j"
89808980
warning extra:00000:unmodified OUT variable "found"

expected/plpgsql_check_active_2.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,8 +2441,8 @@ $$ language plpgsql;
24412441
select * from plpgsql_check_function('tx(int)');
24422442
plpgsql_check_function
24432443
-------------------------------------------------------------------------------------------
2444-
warning:00000:3:statement block:parameter "a" is overlapped
2445-
Detail: Local variable overlap function parameter.
2444+
warning:00000:3:statement block:parameter "a" is shadowed
2445+
Detail: Local variable shadows function parameter.
24462446
warning extra:00000:5:statement block:variable "ax" shadows a previously defined variable
24472447
Hint: SET plpgsql.extra_warnings TO 'shadowed_variables'
24482448
warning:00000:2:DECLARE:unused variable "ax"
@@ -8964,14 +8964,14 @@ begin
89648964
end;
89658965
$$ language plpgsql immutable;
89668966
select * from plpgsql_check_function('fx1');
8967-
plpgsql_check_function
8968-
----------------------------------------------------------------------------
8969-
warning:00000:2:statement block:parameter "found" is overlapped
8970-
Detail: Local auto variable overlap function parameter.
8971-
warning:00000:3:FOR with integer loop variable:parameter "i" is overlapped
8972-
Detail: Local auto variable overlap function parameter.
8973-
warning:00000:5:FOR with integer loop variable:parameter "j" is overlapped
8974-
Detail: Local auto variable overlap function parameter.
8967+
plpgsql_check_function
8968+
--------------------------------------------------------------------------
8969+
warning:00000:2:statement block:parameter "found" is shadowed
8970+
Detail: Local auto variable shadows function parameter.
8971+
warning:00000:3:FOR with integer loop variable:parameter "i" is shadowed
8972+
Detail: Local auto variable shadows function parameter.
8973+
warning:00000:5:FOR with integer loop variable:parameter "j" is shadowed
8974+
Detail: Local auto variable shadows function parameter.
89758975
warning extra:00000:unmodified OUT variable "i"
89768976
warning extra:00000:unmodified OUT variable "j"
89778977
warning extra:00000:unmodified OUT variable "found"

expected/plpgsql_check_passive-18.out

Whitespace-only changes.

0 commit comments

Comments
 (0)