Give a user permission to ALTER a function

廉价感情. 提交于 2019-12-06 05:05:33
Erwin Brandstetter

The manual on ALTER FUNCTION is clear on that:

You must own the function to use ALTER FUNCTION. To change a function's schema, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the function's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the function. However, a superuser can alter ownership of any function anyway.)

Bold emphasis mine.
You also need a couple of basic privileges to create functions. Per documentation:

To be able to define a function, the user must have the USAGEprivilege on the language.
...

To be able to create a function, you must have USAGE privilege on the argument types and the return type.

The simple solution would be make changes to functions as superuser. (Default superuser is postgres, but any user can be made superuser.)

If you really need to change ownership on all functions, this would do the trick:

SELECT string_agg('ALTER FUNCTION '
            || quote_ident(n.nspname) || '.' 
            || quote_ident(p.proname) || '(' 
            || pg_catalog.pg_get_function_identity_arguments(p.oid)
            || ') OWNER TO foo;'
          , E'\n') AS _sql
FROM   pg_catalog.pg_proc p
JOIN   pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE  n.nspname = 'public';
-- AND p.relowner <> (SELECT oid FROM pg_roles WHERE rolname = 'foo')
-- AND p.proname ~~ 'f_%'

Restricted to the public schema.
For more details and explanation refer to this more complete answer on dba.SE.
Also closely related:
DROP FUNCTION without knowing the number/type of parameters?

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