@@ -12,12 +12,24 @@ If you like it and if you would to join to development of this extension, regist
1212yourself to [ postgresql extension hacking] ( https://groups.google.com/forum/#!forum/postgresql-extensions-hacking )
1313google group.
1414
15+ # Features
16+
17+ * check fields of referenced database objects and types inside embedded SQL
18+ * using correct types of function parameters
19+ * unused variables and function argumens, unmodified OUT argumens
20+ * partially detection of dead code (due RETURN command)
21+ * detection of missing RETURN command in function
22+ * try to identify unwanted hidden casts, that can be performance issue like unused indexes
23+ * possibility to collect relations and functions used by function
24+
1525I invite any ideas, patches, bugreports
1626
1727plpgsql_check is next generation of plpgsql_lint. It allows to check source code by explicit call
1828<i >plpgsql_check_function</i >.
1929
20- PostgreSQL 9.2 is required, PostgreSQL 9.3, 9.4, 9.5 and 9.6 are supported
30+ PostgreSQL PostgreSQL 9.4, 9.5, 9.6, 10, 11 are supported (Develop 12 is supported too).
31+
32+ PostgreSQL 9.3 is compileable, but regress tests are not maintained.
2133
2234The SQL statements inside PL/pgSQL functions are checked by validator for semantic errors. These errors
2335can be found by plpgsql_check_function:
@@ -111,6 +123,23 @@ Function plpgsql_check_function() has two possible formats: text or xml
111123 </Function>
112124 (1 row)
113125
126+ ## Options
127+
128+ You can set level of warnings via function's parameters:
129+
130+ * ` fatal_errors boolean DEFAULT true ` - stop on first error
131+
132+ * ` other_warnings boolean DEFAULT true ` - show warnings like different attributes number
133+ in assignmenet on left and right side, variable overlaps function's parameter, unused
134+ variables, unwanted casting, ..
135+
136+ * ` extra_warnings boolean DEFAULT true ` - show warnings like missing ` RETURN ` ,
137+ shadowed variables, dead code, never read (unused) function's parameter,
138+ unmodified variables, ..
139+
140+ * ` performance_warnings boolean DEFAULT false ` - performance related warnings like
141+ declared type with type modificator, casting, implicit casts in where clause (can be
142+ reason why index is not used), ..
114143
115144## Triggers
116145
@@ -156,6 +185,16 @@ triggers. Please, test following queries:
156185 JOIN pg_catalog.pg_language l ON p.prolang = l.oid
157186 WHERE l.lanname = 'plpgsql' AND p.prorettype <> 2279;
158187
188+ or
189+
190+ SELECT p.proname, tgrelid::regclass, cf.*
191+ FROM pg_proc p
192+ JOIN pg_trigger t ON t.tgfoid = p.oid
193+ JOIN pg_language l ON p.prolang = l.oid
194+ JOIN pg_namespace n ON p.pronamespace = n.oid,
195+ LATERAL plpgsql_check_function(p.oid, t.tgrelid) cf
196+ WHERE n.nspname = 'public' and l.lanname = 'plpgsql'
197+
159198or
160199
161200 -- check all plpgsql functions (functions or trigger functions with defined triggers)
@@ -297,6 +336,22 @@ tables. So you can do (with following trick safetly):
297336This trick emulates GLOBAL TEMP tables partially and it allows a statical validation.
298337Other possibility is using a [ template foreign data wrapper] (https://github.com/okbob/template_fdw )
299338
339+ # Dependency list
340+
341+ A function <i >plpgsql_show_dependency_tb</i > can show all functions and relations used
342+ inside processed function:
343+
344+ postgres=# select * from plpgsql_show_dependency_tb('testfunc(int,float)');
345+ ┌──────────┬───────┬────────┬─────────┬────────────────────────────┐
346+ │ type │ oid │ schema │ name │ params │
347+ ╞══════════╪═══════╪════════╪═════════╪════════════════════════════╡
348+ │ FUNCTION │ 36008 │ public │ myfunc1 │ (integer,double precision) │
349+ │ FUNCTION │ 35999 │ public │ myfunc2 │ (integer,double precision) │
350+ │ RELATION │ 36005 │ public │ myview │ │
351+ │ RELATION │ 36002 │ public │ mytable │ │
352+ └──────────┴───────┴────────┴─────────┴────────────────────────────┘
353+ (4 rows)
354+
300355# Compilation
301356
302357You need a development environment for PostgreSQL extensions:
@@ -387,12 +442,13 @@ or compile by self:
387442 1 . copy ` plpgsql_check.dll ` to ` PostgreSQL\9.3\lib `
388443 2 . copy ` plpgsql_check.control ` and ` plpgsql_check--0.8.sql ` to ` PostgreSQL\9.3\share\extension `
389444
390-
391445## Checked on
392446
393447* gcc on Linux (against all supported PostgreSQL)
394448* clang 3.4 on Linux (against PostgreSQL 9.5)
395- * for success regress tests the PostgreSQL 9.2.14, 9.3.10, 9.4.5, 9.5 or 9.6 is required.
449+ * for success regress tests the PostgreSQL 9.3.10, 9.4.5, 9.5 or higher is required
450+
451+ Compilation against PostgreSQL 10 requires libICU!
396452
397453# Licence
398454
0 commit comments