Skip to content

Commit 3c6fb7d

Browse files
committed
support PostgreSQL 19
1 parent 9706c82 commit 3c6fb7d

File tree

5 files changed

+523
-0
lines changed

5 files changed

+523
-0
lines changed
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_passive-19.out

Whitespace-only changes.

postgresql19-plpgsql_check.spec

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
%global pgmajorversion 19
2+
%global pginstdir /usr/pgsql-19
3+
%global sname plpgsql_check
4+
5+
Name: %{sname}_%{pgmajorversion}
6+
Version: 2.8.1
7+
Release: 1%{?dist}
8+
Summary: Additional tools for plpgsql functions validation
9+
10+
Group: Applications/Databases
11+
License: BSD
12+
URL: https://github.com/okbob/plpgsql_check/archive/v%{version}.zip
13+
Source0: plpgsql_check-%{version}.zip
14+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
15+
16+
BuildRequires: postgresql%{pgmajorversion}-devel
17+
Requires: postgresql%{pgmajorversion}
18+
19+
%description
20+
The plpgsql_check is PostgreSQL extension with functionality for direct
21+
or indirect extra validation of functions in plpgsql language. It verifies
22+
a validity of SQL identifiers used in plpgsql code. It try to identify
23+
a performance issues.
24+
25+
%prep
26+
%setup -q -n %{sname}-%{version}
27+
28+
29+
%build
30+
PATH="%{pginstdir}/bin;$PATH" ; export PATH
31+
CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS
32+
make USE_PGXS=1 PG_CONFIG=%{pginstdir}/bin/pg_config %{?_smp_mflags}
33+
34+
%install
35+
rm -rf %{buildroot}
36+
make install DESTDIR=%{buildroot} PG_CONFIG=%{pginstdir}/bin/pg_config %{?_smp_mflags}
37+
38+
%clean
39+
rm -rf %{buildroot}
40+
41+
%files
42+
%defattr(644,root,root,755)
43+
%doc README.md
44+
%{pginstdir}/lib/plpgsql_check.so
45+
%{pginstdir}/share/extension/plpgsql_check--2.1.sql
46+
%{pginstdir}/share/extension/plpgsql_check.control
47+
%{pginstdir}/lib/bitcode/*.bc
48+
%{pginstdir}/lib/bitcode/plpgsql_check/src/*.bc
49+
%{pginstdir}/share/extension/*.control
50+
51+
%changelog
52+
* Tue Mar 18 2025 - Pavel Stehule <pavel.stehule@gmail.com> 2.8.0
53+
- remove support for PostgreSQL 12 and 13
54+
55+
* Wed Dec 6 2023 - Pavel Stehule <pavel.stehule@gmail.com> 2.7.0
56+
- unclosed cursors detection
57+
58+
* Tue Oct 31 2023 - Pavel Stehule <pavel.stehule@gmail.com> 2.6.0
59+
- simple constant tracing support
60+
61+
* Sat Apr 29 2023 - Pavel Stehule <pavel.stehule@gmail.com> 2.4.0
62+
- remove support for PostgreSQL 10 and 11
63+
64+
* Wed Jan 11 2023 - Pavel Stehule <pavel.stehule@gmail.com> 2.3.0
65+
- possibility to detect compatibility issues (obsolete setting of refcursor)
66+
67+
* Tue Sep 20 2022 - Pavel Stehule <pavel.stehule@gmail.com> 2.2.0
68+
- possibility to use in comment options
69+
70+
* Wed Dec 29 2021 - Pavel Stehule <pavel.stehule@gmail.com> 2.1.0
71+
- possibility to count statement's aborted execution
72+
- possibility to count "unfinished" statements due exception
73+
74+
* Mon Sep 27 2021 - Pavel Stehule <pavel.stehule@gmail.com> 2.0.0
75+
- pragma type for setting type to record variable
76+
- pragma table for creating ephemeral table
77+
78+
* Mon Jun 21 2021 - Pavel Stehule <pavel.stehule@gmail.com> 1.17.0
79+
- remove support for PostgreSQL 9.5 and 9.6
80+
81+
* Sat Mar 6 2021 - Pavel Stehule <pavel.stehule@gmail.com> 1.16.0
82+
- plpgsql_profiler_functions_all
83+
84+
* Mon Nov 16 2020 - Pavel Stehule <pavel.stehule@gmail.com> 1.14.0
85+
- queryid can be displayed in profiler's reports (Julien Rouhaud)
86+
- new profiler's GUC plpgsql_check.profiler_max_shared_chunks (Julien Rouhaud)
87+
- few minor bugfixes
88+
89+
* Fri Aug 14 2020 - Pavel Stehule <pavel.stehule@gmail.com> 1.13.0
90+
- tracer
91+
- pragma support to control checks, warnings and tracing
92+
93+
* Thu Jul 2 2020 - Pavel STEHULE <pavel.stehule@gmail.com> 1.11.0
94+
- possibility to check functions with arguments of polymorphic type
95+
- possibility to specify type used as real type instead polymorphic type
96+
97+
* Fri Jun 05 2020 - Pavel STEHULE <pavel.stehule@gmail.com> 1.10.0
98+
- deduction record type structure from result of polymorphic function
99+
100+
* Mon Apr 27 2020 - Pavel STEHULE <pavel.stehule@gmail.com> 1.9.1
101+
- minor bugfixes
102+
103+
* Mon Mar 30 2020 - Pavel STEHULE <pavel.stehule@gmail.com> 1.9.0
104+
- statement and branch coverage metrics
105+
- remove support for Postgres 9.4
106+
107+
* Mon Jan 06 2020 - Pavel STEHULE <pavel.stehule@gmail.com> 1.8.2
108+
- fix of compilation issue
109+
110+
* Sun Jan 05 2020 - Pavel STEHULE <pavel.stehule@gmail.com> 1.8.1
111+
- cleaner detection function oid from name or signature
112+
113+
* Sun Dec 29 2019 - Pavel STEHULE <pavel.stehule@gmail.com> 1.8.0
114+
- use Postgres tool for calling functions from plpgsql library instead dynamic linking
115+
- it solve issues related to dependency plpgsq_check on plpgsql
116+
117+
* Mon Sep 23 2019 - Pavel STEHULE <pavel.stehule@gmail.com> 1.7.6
118+
- fix false alarm - multiple plans in EXECUTE statement, and possible crash
119+
120+
* Tue Sep 10 2019 - Pavel STEHULE <pavel.stehule@gmail.com> 1.7.5
121+
- allow some work on tables with rules
122+
123+
* Wed Jul 24 2019 - Pavel STEHULE <pavel.stehule@gmail.com> 1.7.3
124+
- profiler bugfixes
125+
126+
* Tue May 21 2019 - Pavel STEHULE <pavel.stehule@gmail.com> 1.7.2
127+
- profiler bugfixes
128+
129+
* Fri Apr 26 2019 - Pavel STEHULE <pavel.stehule@gmail.com> 1.7.1
130+
- bugfixes
131+
132+
* Wed Apr 17 2019 - Pavel STEHULE <pavel.stehule@gmail.com> 1.7.0
133+
- check of format of fmt string of "format" function
134+
- better check of dynamic SQL when it is const string
135+
- check of SQL injection vulnerability of stmt expression at EXECUTE stmt
136+
137+
* Sun Dec 23 2018 - Pavel STEHULE <pavel.stehule@gmail.com> 1.4.2-1
138+
- metada fix
139+
140+
* Fri Dec 21 2018 - Pavel STEHULE <pavel.stehule@gmail.com> 1.4.1-1
141+
- minor bugfixes
142+
143+
* Sun Dec 2 2018 - Pavel STEHULE <pavel.stehule@gmail.com> 1.4.0-1
144+
- possible to show function's dependency on functions and tables
145+
- integrated profiler
146+
- bug fixes (almost false alarms)
147+
148+
* Wed Jun 6 2018 - Pavel STEHULE <pavel.stehule@gmail.com> 1.2.3-1
149+
- PostgreSQL 11 support
150+
- detect hidden casts in expressions
151+
152+
* Thu Oct 26 2017 - Pavel STEHULE <pavel.stehule@gmail.com> 1.2.2-1
153+
- never read variables detection
154+
- fix false alarm on MOVE command
155+
156+
* Fri Sep 15 2017 - Pavel STEHULE <pavel.stehule@gmail.com> 1.2.1-1
157+
- missing RETURN detection
158+
- fix some bugs and false alarms
159+
- PostgreSQL 11 support
160+
161+
* Fri Nov 11 2016 - Pavel STEHULE <pavel.stehule@gmail.com> 1.2.0-1
162+
- support extra warnings - shadowed variables
163+
164+
* Thu Aug 25 2016 - Pavel STEHULE <pavel.stehule@gmail.com> 1.0.5-1
165+
- minor fixes, support for PostgreSQL 10
166+
167+
* Fri Apr 15 2016 - Pavel STEHULE <pavel.stehule@gmail.com> 1.0.4-1
168+
- support for PostgreSQL 9.6
169+
170+
* Mon Oct 12 2015 - Pavel STEHULE <pavel.stehule@gmail.com> 1.0.3-1
171+
- fix false alarms of unused cursor variables
172+
- fix regress tests
173+
174+
* Thu Jul 09 2015 - Pavel STEHULE <pavel.stehule@gmail.com> 1.0.2-2
175+
- bugfix release
176+
177+
* Fri Dec 19 2014 - Pavel STEHULE <pavel.stehule@gmail.com> 0.9.3-1
178+
- fix a broken record field type checking
179+
- add check for assign to array field
180+
181+
* Mon Aug 25 2014 - Pavel STEHULE <pavel.stehule@gmail.com> 0.9.1-1
182+
- Initial packaging

0 commit comments

Comments
 (0)