Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find dependency between PostgreSQL functions?

Tags:

sql

postgresql

I'm using PostgreSQL 9.2.10

Suppose you have 2 PostgreSQL functions, 'called_function' and 'caller_function', second one is calling the first one. Exactly:

CREATE FUNCTION called_function () RETURNS varchar AS
$BODY$
BEGIN
  RETURN 'something';
END;

CREATE FUNCTION caller_function () RETURNS varchar AS
$BODY$
BEGIN
  RETURN called_function ();
END;

Now, using SQL and knowing only function name, I would like to find out if 'caller_function' calls some other function. Or if 'called_function' is called by some other function. Is it possible?

I tried to get function's OID (let's say it is '123') and then I looked into pg_depend table:

SELECT * FROM pg_catalog.pg_depend dep WHERE dep.objid = 123 OR dep.objsubid = 123 OR dep.refobjid = 123 OR dep.refobjsubid = 123 OR dep.refobjsubid = 123;

But it finds only pg_language and pg_namespace dependency. Nothing more.

like image 743
user6129679 Avatar asked Nov 08 '22 17:11

user6129679


1 Answers

I had same problem to define a function and because of dependency It didn't work. Then I solved my problem with adding this command before the commands

SET check_function_bodies = false;

hope to help someone else

like image 114
vatandoost Avatar answered Nov 14 '22 23:11

vatandoost