Query goal: | Make sure that there is genuine overloading instead of duplication or dead code. "In some programming languages, function overloading or method overloading is the ability to create multiple functions of the same name with different implementations." (Wikipedia) In PostgreSQL one can do it automagically by having multiple routines with the same name but different parameters in the same schema. |
Notes about the query: | 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 routines that are a part of an extension. |
Query type: | General (Overview of some aspect of the database.) |
Query license: | MIT License |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
WITH routines AS (SELECT specific_schema, translate(substring(specific_name,'_[0-9]+$'),'_','')::int::oid AS routine_oid, routine_name, routine_type FROM information_schema.routines 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 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 = routines.specific_name)) SELECT specific_schema, routine_name, routine_type, Count(*) AS number_of_routines, string_agg(CASE WHEN pg_get_function_identity_arguments(routine_oid)='' THEN 'No parameters' ELSE pg_get_function_identity_arguments(routine_oid) END, ';<br>' ) AS parameters FROM routines GROUP BY specific_schema, routine_name, routine_type HAVING Count(*)>1 ORDER BY specific_schema, routine_name, routine_type; |
Collection name | Collection description |
---|---|
Find problems by overview | Queries that results point to different aspects of database that might have problems. A human reviewer has to decide based on the results as to whether there are problems or not . |
Category name | Category description |
---|---|
Comfortability of database evolution | Queries of this category provide information about the means that influence database evolution. |
Duplication of implementation elements | Queries of this catergory provide information about the duplication of the database objects. |
Overloading | Queries of this category provide information about overloading of routines. |
User-defined routines | Queries of this category provide information about the user-defined routines |
Reference |
---|
https://en.wikipedia.org/wiki/Function_overloading |
https://www.postgresql.org/docs/current/xfunc-overload.html |