Query goal: | For the sake of making code better understandable follow naming conventions. |
Notes about the query: | The query does not consider the routines that are a part of an extension. In the output data the query removes from the end of the routine name the numbers, which represent the object identifier of the routine in the system catalog. There could be multiple routines with the same name but with different parameters in the same schema (overloading). Thus, for the unique identification of the routine it is necessary to present also its parameters in addition to the schema name and routine name. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | High (Few or no false-positive results) |
Query license: | MIT License |
Fixing suggestion: | Drop the routine and recreate with the improved parameter names. |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
WITH params AS (SELECT specific_schema AS routine_schema, regexp_replace(specific_name,'_[0-9]*$','') AS routine_name, pg_get_function_identity_arguments(translate(substring(specific_name,'_[0-9]+$'),'_','')::int::oid) AS parameters, ordinal_position, data_type, parameter_mode, parameter_name FROM information_schema.parameters WHERE parameter_mode IN ('IN','INOUT') AND specific_schema NOT IN (SELECT schema_name FROM INFORMATION_SCHEMA.schemata WHERE schema_name<>'public' AND schema_owner='postgres' AND schema_name IS NOT NULL) AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d inner join pg_catalog.pg_proc pc ON d.objid=pc.oid WHERE EXISTS (SELECT 1 FROM pg_catalog.pg_extension e WHERE d.refobjid=e.oid) AND pc.proname || '_' || pc.oid = parameters.specific_name)) SELECT routine_schema, routine_name, parameters, ordinal_position, data_type, parameter_mode, parameter_name FROM params WHERE routine_name NOT IN ('f_assume_you_must_use_files', 'f_check_format_comma_separated_list', 'f_check_password', 'f_default_value_with_no_match') AND parameter_name NOT LIKE 'p\_%' AND parameter_name NOT LIKE '\_%' ORDER BY routine_schema, routine_name, parameters, ordinal_position; |
Collection name | Collection 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 . |
Category name | Category description |
---|---|
Naming | Queries of this category provide information about the style of naming. |
User-defined routines | Queries of this category provide information about the user-defined routines |
Reference |
---|
https://www.cybertec-postgresql.com/en/choose-plpgsql-variable-names-wisely/ |