plpgsql_check
plpgsql_check
plpgsql_check : extended check for plpgsql functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3060 | plpgsql_check
|
plpgsql_check
|
2.8.11 |
LANG
|
MIT
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd--
|
No
|
Yes
|
Yes
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Requires | plpgsql
|
| See Also | pldbgapi
plprofiler
pg_hint_plan
pgtap
auto_explain
plv8
plperl
plpython3u
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG
|
2.8.11 |
18
17
16
15
14
|
plpgsql_check |
plpgsql |
| RPM | PGDG
|
2.8.10 |
18
17
16
15
14
|
plpgsql_check_$v |
- |
| DEB | PGDG
|
2.8.11 |
18
17
16
15
14
|
postgresql-$v-plpgsql-check |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
el8.aarch64
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
el9.x86_64
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
el9.aarch64
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
el10.x86_64
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
el10.aarch64
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
PGDG 2.8.10
|
d12.x86_64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
d12.aarch64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
d13.x86_64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
d13.aarch64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
u22.x86_64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
u22.aarch64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
u24.x86_64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
u24.aarch64
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
PGDG 2.8.11
|
Source
Install
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install plpgsql_check; # install via package name, for the active PG version
pig install plpgsql_check -v 18; # install for PG 18
pig install plpgsql_check -v 17; # install for PG 17
pig install plpgsql_check -v 16; # install for PG 16
pig install plpgsql_check -v 15; # install for PG 15
pig install plpgsql_check -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'plpgsql_check';Create this extension with:
CREATE EXTENSION plpgsql_check CASCADE; -- requires plpgsqlUsage
plpgsql_check is a linter and checker for PL/pgSQL functions that detects errors at development time rather than runtime.
CREATE EXTENSION plpgsql_check;Check a Function
SELECT * FROM plpgsql_check_function('my_function()');
SELECT * FROM plpgsql_check_function('my_function(int, text)');
SELECT * FROM plpgsql_check_function('my_function()', fatal_errors := false);Output Formats
SELECT * FROM plpgsql_check_function('fx()', format := 'text');
SELECT * FROM plpgsql_check_function('fx()', format := 'json');
SELECT * FROM plpgsql_check_function('fx()', format := 'xml');Check Trigger Functions
-- Trigger functions need the associated table
SELECT * FROM plpgsql_check_function('my_trigger_func()', 'my_table');
-- With transition tables
SELECT * FROM plpgsql_check_function(
'my_trigger_func()', 'my_table',
newtable := 'newtab', oldtable := 'oldtab'
);Warning Categories
SELECT * FROM plpgsql_check_function('fx()',
extra_warnings := true, -- dead code, unused parameters
performance_warnings := true, -- index and casting issues
security_warnings := true, -- SQL injection checks
compatibility_warnings := true -- obsolete patterns
);Batch Check All Functions
SELECT p.oid, p.proname, plpgsql_check_function(p.oid)
FROM pg_catalog.pg_namespace n
JOIN pg_catalog.pg_proc p ON pronamespace = n.oid
JOIN pg_catalog.pg_language l ON p.prolang = l.oid
WHERE l.lanname = 'plpgsql' AND p.prorettype <> 2279;Passive Mode (Check on Execution)
LOAD 'plpgsql_check';
SET plpgsql_check.mode = 'every_start'; -- check before each executionOr in postgresql.conf:
shared_preload_libraries = 'plpgsql,plpgsql_check'
plpgsql_check.mode = 'every_start'Profiler
-- Enable profiling
SELECT plpgsql_check_profiler(true);
-- Execute functions to collect data
SELECT my_function();
-- View per-line execution times
SELECT lineno, avg_time, source
FROM plpgsql_profiler_function_tb('my_function()');
-- Per-statement profile
SELECT stmtid, parent_stmtid, lineno, exec_stmts, stmtname
FROM plpgsql_profiler_function_statements_tb('my_function()');
-- All function statistics
SELECT * FROM plpgsql_profiler_functions_all();
-- Reset profiling data
SELECT plpgsql_profiler_reset_all();Dependency Tracking
SELECT * FROM plpgsql_show_dependency_tb('my_function(int)');Coverage Metrics
SELECT * FROM plpgsql_coverage_statements('my_function()');
SELECT * FROM plpgsql_coverage_branches('my_function()');Pragma Directives
Embed checking options in function comments:
CREATE OR REPLACE FUNCTION fx(anyelement) RETURNS text AS $$
BEGIN
/* @plpgsql_check_options: anyelementtype = text */
RETURN $1;
END;
$$ LANGUAGE plpgsql;Last updated on