Find parameters of routines that have the same name but a different type. Parameters that have the same name should have, in general, the same data type as well, assuming that the routines, which have the parameters, have different names, i.e., there is no overloading in play.
Notes
In case of the string_agg function, the line break (br) tag is used as a part of the separator for the better readability in case the query result is displayed in a web browser. The query does not consider the routines that are a part of an extension.
Type
Problem detection (Each row in the result could represent a flaw in the design)
Change the type of the parameter or the name of the parameter by dropping the routines and recreating these.
Data Source
INFORMATION_SCHEMA+system catalog
SQL Query
WITH data_types AS (SELECT specific_schema, specific_name,
regexp_replace(specific_name,'_[0-9]*$','') AS routine_name,
pg_get_function_identity_arguments(translate(substring(specific_name,'_[0-9]+$'),'_','')::int::oid) AS parameters,
parameter_name,
CASE WHEN data_type='numeric' THEN data_type || '(' || numeric_precision || ',' || numeric_scale || ')'
WHEN character_maximum_length IS NOT NULL THEN data_type || '(' || character_maximum_length || ')'
WHEN datetime_precision IS NOT NULL AND data_type<>'date' THEN data_type || '(' || datetime_precision || ')'
ELSE data_type END AS data_type
FROM INFORMATION_SCHEMA.parameters
WHERE regexp_replace(specific_name,'_[0-9]*$','') NOT IN ('f_assume_you_must_use_files', 'f_check_format_comma_separated_list', 'f_check_password', 'f_default_value_with_no_match') 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 parameter_name, string_agg(specific_schema ||'.'|| routine_name || '(' || parameters || ')' || ' ' || Upper(data_type),'; ' ORDER BY data_type, specific_schema, specific_name) AS types
FROM data_types AS dt
WHERE EXISTS (SELECT 1 FROM data_types AS dt2 WHERE dt.routine_name<>dt2.routine_name AND dt.parameter_name=dt2.parameter_name
AND dt.data_type<>dt2.data_type)
GROUP BY parameter_name
ORDER BY parameter_name;
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
Data types
Queries of this category provide information about the data types and their usage.
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
Further reading and related materials:
Reference
The corresponding code smell in case of cleaning code is "G11: Inconsistency". (Robert C. Martin, Clean Code)