Query goal: | Find routine parameter names that contain the routine name. Names of routine parameters shouldn't contain the name of the routine. It makes the names too long. A routine cannot have two parameters with the same name. |
Notes about the query: | The query does not consider the routines that are a part of an extension. The query uses bold (b) tags to highlight the parts of parameter names that violate the suggestion. 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. |
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 it with the improved parameter names. Use a consistent style of naming. |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
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, regexp_replace(parameter_name, regexp_replace(specific_name,'_[0-9]*$',''), '<b>' || regexp_replace(specific_name,'_[0-9]*$','') || '</b>','g') AS suspected_parameter FROM information_schema.parameters WHERE 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 parameter_name ILIKE '%' || regexp_replace(specific_name,'_[0-9]*$','') || '%' 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) ORDER BY routine_schema, routine_name, parameters, parameter_name; |
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 |
---|
The corresponding code problem in case of cleaning code is "Don’t Add Gratuitous Context". (Robert C. Martin, Clean Code) |