The list of all the queries

Inconsistent use of functions and procedures

Query goal: 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.
Query type: Problem detection (Each row in the result could represent a flaw in the design)
Query reliability: Medium (Medium number of false-positive results)
Query license: MIT License
Data source: INFORMATION_SCHEMA+system catalog
SQL query: Click on query to copy it

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]','<br>','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),'<','&lt','g'),'[\r\n]','<br>','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 where the query belongs to

Collection nameCollection description
Find problems automaticallyQueries, 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 where the query belongs to

Category nameCategory description
InconsistenciesQueries of this catergory provide information about inconsistencies of solving the same problem in different places.
User-defined routinesQueries of this category provide information about the user-defined routines

The list of all the queries