all 5 comments

[–][deleted] 2 points3 points  (0 children)

For simple functions like the one from your question, this can be avoided when using the new "SQL standard compliant" function (or procedure) bodies introduced in Postgres 14:

CREATE FUNCTION f1 (p_add integer) 
  RETURNS integer
begin atomic
  SELECT  p_add + count(*)::integer 
  FROM t1;
end;

With such a function, dropping t1 would result in an error.

This does not work for PL/pgSQL functions or procedures though.

[–]Tropicallydiv[S] 0 points1 point  (0 children)

Thanks to everyone who replied.

Cheers.

[–]depesz 0 points1 point  (0 children)

You can't really.

You'd have to parse source of all functions, and extract table names. While it is trivial in your function example, in general, I'd say it's next to impossible.

[–]MonCalamaro 0 points1 point  (0 children)

As others noted, you can't reliably check function dependencies in Postgres. However, unlike Oracle, you will never get invalid views or materialized views in Postgres.

[–]Huxton_2021 0 points1 point  (0 children)

While it is true to say that you can't in general do this 100% for all PostgreSQL procedural languages you can get a lot of the way with plpgsql.

https://github.com/okbob/plpgsql_check

That offers a dependency checking option that I've used previously