如何检查哪个函数使用类型? [英] How to check which function uses a type?
问题描述
我有一个想要更改的类型,但是我不知道还有谁在使用它。
I have a type which I'd like to change but I don't know who else is using it.
如何检查所有返回的函数这种类型?
How can I check for all functions that return this type?
推荐答案
您可以在系统目录 pg_depend
。
You can find all dependencies in the system catalog pg_depend
.
这将返回 所有函数,具体取决于类型 。即不仅具有 RETURNS
子句中类型的那些,而且还具有类型作为函数参数的那些:
This returns all functions depending on the type. I.e. not only those with the type in the RETURNS
clause, but also those with the type as function parameter:
SELECT objid::regproc AS function_name
, pg_get_functiondef(objid) AS function_definition
, pg_get_function_identity_arguments(objid) AS function_args
, pg_get_function_result(objid) AS function_returns
FROM pg_depend
WHERE refclassid = 'pg_type'::regclass
AND refobjid = 'my_type'::regtype -- insert your type name here
AND classid = 'pg_proc'::regclass; -- only find functions
这也适用于表函数:
...
RETURNS TABLE (foo my_type, bar int)
使用系统目录信息功能。
可能还有其他依赖关系(不依赖功能)。从我的查询中删除最后一个 WHERE
条件进行测试(并显然修改 SELECT
列表)。
There may be other dependencies (not to functions). Remove the last WHERE
condition from my query to test (and adapt the SELECT
list, obviously).
并且仍然有可能在函数主体或动态SQL中的查询中显式使用该类型(例如在强制转换中)。您只能通过解析函数主体的文本来识别此类用例。在系统中没有注册任何显式依赖项。
And there is still the possibility of the type being used explicitly (in a cast for instance) in queries in the function body or in dynamic SQL. You can only identify such use cases by parsing the text of the function body. There are no explicit dependencies registered in the system.
相关:
- < a href = https://stackoverflow.com/questions/12127274/how-to-get-function-parameter-lists-so-i-can-drop-a-function/12127714#12127714>如何获取函数参数列表(以便删除函数)
- 不知道参数的数量/类型的拖放功能?
- How to get function parameter lists (so I can drop a function)
- DROP FUNCTION without knowing the number/type of parameters?
这篇关于如何检查哪个函数使用类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!