Query goal: | Find for each user schema that contain a SQL-language routine how many of these have the body that is string literal and how many have the body (possible starting from PostgreSQL 14) that is parsed at the routine definition time. Try to be consistent, i.e., use the same solution in case of all the routines. |
Notes about the query: | The query does not work before PostgreSQL 14. |
Query type: | Sofware measure (Numeric values (software measures) about the database) |
Query license: | MIT License |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
SELECT pg_namespace.nspname AS routine_schema, Count(*) FILTER (WHERE prosqlbody IS NULL) AS number_of_sql_routines_where_body_is_literal, Count(*) FILTER (WHERE prosqlbody IS NOT NULL) AS number_of_sql_routines_where_body_is_sql_body FROM pg_catalog.pg_proc, pg_catalog.pg_namespace, pg_catalog.pg_language WHERE pg_proc.pronamespace = pg_namespace.oid AND pg_proc.prolang = pg_language.oid AND pg_language.lanname='sql' AND pg_namespace.nspname 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 WHERE EXISTS (SELECT 1 FROM pg_catalog.pg_extension e WHERE d.refobjid=e.oid) AND d.objid=pg_proc.oid) GROUP BY pg_namespace.nspname; |
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 |
---|---|
Does not work in some earlier PostgreSQL version | Queries of this category provide information that was not available in some earlier PostgreSQL version |
User-defined routines | Queries of this category provide information about the user-defined routines |
Reference |
---|
https://www.cybertec-postgresql.com/en/better-sql-functions-in-postgresql-v14/ |