How to make an extension not relocatable?

混江龙づ霸主 提交于 2020-06-06 08:30:32

问题


I have an extension: https://github.com/CraigTyle/Mathexp

My task is to make the extension not relocatable: it should be possible to install the extension in any schema, but it should be impossible to change that schema.

I was told that this is how to do it: Do not use operators and use the @extschema@ prefix for locally defined types and objects. well don't declare relocatable extension.

What exactly do I have to do?


回答1:


First, you have to change relocatable to false in the extension's control file.

Other than that, the recommendation you got is partly reasonable and partly nonsense.

You should define your functions like this:

CREATE FUNCTION .... AS
$$ /* function body */ $$
SET search_path = @extschema@;

Then the search_path is fixed to pg_catalog, pg_temp and your extension schema for the duration of the function call. That means that all access to objects without an explicit schema will only search in these schemas.

Then you don't have to worry about explicitly qualifying everything in the function with @extschema@, and you can use operators without having to worry, because search_path applies to operators as well. (You can also schema-qualify operators: OPERATOR(schema.+), but that's obviously painful and harms readability.)



来源:https://stackoverflow.com/questions/62182984/how-to-make-an-extension-not-relocatable

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