Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@smbarbour
Created February 23, 2016 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smbarbour/dbfc57e2b1f4cb95b30f to your computer and use it in GitHub Desktop.
Save smbarbour/dbfc57e2b1f4cb95b30f to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION meta_find_references(tablename text)
RETURNS TABLE (type text, name text)
AS $$
SELECT 'View', table_name FROM information_schema.views WHERE view_definition ~* $1
UNION
SELECT 'Function', routine_name FROM information_schema.routines WHERE routine_definition ~* $1
ORDER BY 1, 2
$$
LANGUAGE SQL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment