Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: getting all functions related to table

Tags:

sql

postgresql

I have this function:

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) ~ '\mTableName\M';

it gives me a list of functions that uses TableName. However it doesn't ignore notes. For example if in function A there will be a line like:

-- select * from TableName

it will show A in the result even though its a note and A doesn't really uses TableName.

How can I make a query that does the same thing but ignore all notes?

like image 322
John Avatar asked Dec 19 '25 08:12

John


1 Answers

You may find everything you need directly on this wiki page : https://wiki.postgresql.org/wiki/Pg_depend_display

There is all sorts of dependency views depending on you PostgreSQL version.

like image 123
Clément Prévost Avatar answered Dec 21 '25 23:12

Clément Prévost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!