Skip to content

Instantly share code, notes, and snippets.

@chetanppatil
Created April 24, 2018 11:07
Show Gist options
  • Save chetanppatil/a1497726fcf456b3131a98f1e839b08e to your computer and use it in GitHub Desktop.
Save chetanppatil/a1497726fcf456b3131a98f1e839b08e to your computer and use it in GitHub Desktop.
Get all functions depending on specified table in postgre
/* HERE
table name is "my_table"
\m and \M mark the beginning and end of a word in the regexp match.
*/
SELECT n.nspname AS schema_name
,p.proname AS function_name
,pg_get_function_arguments(p.oid) AS args
,pg_get_functiondef(p.oid) AS func_def
FROM (SELECT oid, * FROM pg_proc p WHERE NOT p.proisagg) p
JOIN pg_namespace n ON n.oid = p.pronamespace
WHERE n.nspname !~~ 'pg_%'
AND n.nspname <> 'information_schema'
AND pg_get_functiondef(p.oid) ~ '\mmy_table\M';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment