Get functions DDL command

做~自己de王妃 提交于 2020-01-06 23:49:06

问题


I need to get DDL of every function in my db for versioning purpose. Here is the query, but it works only for functions in public schema. When I'm trying to use it to get create of functions which exists in public and match schema I get error that subquery returns too many rows.

By checking all values from pg_proc using this query:

select * from pg_proc where proname = 'match_group_1_3_2';

Only values that changes is pronamespace:

How to distinguish both (or more) function? How to distinguish them if they are in the same schema but with different arguments? (by overloading)

I need to use native postgres catalog, not ANSI type - due to performance issues.


回答1:


There are more system catalog information functions to give you the additional information.
And you can get the schema name from the system table pg_namespace:

SELECT n.nspname AS schema_name
      ,p.proname AS function_name
      ,pg_get_functiondef(p.oid) AS func_def
      ,pg_get_function_arguments(p.oid) AS args
      ,pg_get_function_result(p.oid) AS result
FROM   pg_proc p
JOIN   pg_namespace n ON n.oid = p.pronamespace
WHERE  p.proname ILIKE '%match_group_1_3_2%';

This should find functions in any schema in the database.



来源:https://stackoverflow.com/questions/17109073/get-functions-ddl-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!