Find as to whether the database has both procedures as well as functions that do not return a value (i.e., return VOID). Such routines are generally used to modify data in the database. The support of procedures was added to PostgreSQL 11.
Type
Problem detection (Each row in the result could represent a flaw in the design)
WITH void_functions AS (SELECT
n.nspname AS routine_schema,
pr.proname AS routine_name,
pg_get_function_identity_arguments(pr.oid) AS parameters,
regexp_replace(pg_get_functiondef(pr.oid),'[\r\n]',' ','g') AS routine_src,
l.lanname AS routine_language,
'FUNCTION' AS routine_type
FROM
pg_catalog.pg_proc pr,
pg_catalog.pg_namespace n,
pg_catalog.pg_language l,
pg_catalog.pg_type t
WHERE
pr.pronamespace = n.oid
AND pr.prolang=l.oid
AND pr.prorettype=t.oid
AND pr.prokind='f'
AND t.typname='void'
AND pr.proname NOT IN ('f_assume_you_must_use_files', 'f_check_format_comma_separated_list', 'f_check_password', 'f_default_value_with_no_match')
AND n.nspname NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)),
procedures AS (SELECT
n.nspname AS routine_schema,
pr.proname AS routine_name,
pg_get_function_identity_arguments(pr.oid) AS parameters,
regexp_replace( regexp_replace(pg_get_functiondef(pr.oid),'<','<','g'),'[\r\n]',' ','g') AS routine_src,
l.lanname AS routine_language,
'PROCEDURE' AS routine_type
FROM
pg_catalog.pg_proc pr,
pg_catalog.pg_namespace n,
pg_catalog.pg_language l
WHERE
pr.pronamespace = n.oid
AND pr.prolang=l.oid
AND pr.prokind='p'
AND pg_get_function_identity_arguments(pr.oid)~'(IN){0,1}OUT '
AND pr.proname NOT IN ('f_assume_you_must_use_files', 'f_check_format_comma_separated_list', 'f_check_password', 'f_default_value_with_no_match')
AND n.nspname NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)),
routines_union AS (SELECT routine_schema, routine_name, parameters, routine_src, routine_language, routine_type
FROM void_functions
UNION SELECT routine_schema, routine_name, parameters, routine_src, routine_language, routine_type
FROM procedures)
SELECT routine_schema, routine_name, parameters, routine_src, routine_language, routine_type
FROM routines_union
WHERE EXISTS (SELECT * FROM void_functions)
AND EXISTS (SELECT * FROM procedures)
ORDER BY routine_schema, routine_name, parameters;
Collections
This query belongs to the following collections:
Name
Description
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
Categories
This query is classified under the following categories:
Name
Description
Inconsistencies
Queries of this catergory provide information about inconsistencies of solving the same problem in different places.
User-defined routines
Queries of this category provide information about the user-defined routines