How to alter owner of a function in postgres

冷暖自知 提交于 2019-12-03 16:16:32

Is there any way to list down parameters' data type in each of the function.

Yes, use the pg_get_function_identity_arguments() function:

The following will create a SQL script to alter all functions from the someschema schema:

select 'alter function '||nsp.nspname||'.'||p.proname||'('||pg_get_function_identity_arguments(p.oid)||') owner to newowner;'
from pg_proc p
  join pg_namespace nsp ON p.pronamespace = nsp.oid
where nsp.nspname = 'someschema';

You can spool the output of that into a file and then run that generated script.

If you have function names that would require quoting, you probably need to use quote_ident to concatenate the function names.

You can wrap all that into a function and use dynamic SQL to make life easier if you need this on a regular basis.

I had the same problem but pg_get_function_identity_arguments(p.oid) didn't work for me. So I replaced that function with oidvectortypes(p.proargtypes).

select 'alter function '||nsp.nspname||'.'||p.proname||'('||oidvectortypes(p.proargtypes)||') owner to newowner;'
from pg_proc p 
join pg_namespace nsp ON p.pronamespace = nsp.oid
where nsp.nspname = 'someschema';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!