问题描述
我有一个扩展名: 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.
这是怎么做的:不要使用运算符,并且对本地定义的类型和对象使用@extschema@
前缀.最好不要声明可重定位的扩展名.
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.
我该怎么办?
推荐答案
首先,您必须在扩展程序的控制文件中将relocatable
更改为false
.
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.
您应该这样定义函数:
CREATE FUNCTION .... AS
$$ /* function body */ $$
SET search_path = @extschema@;
然后search_path
在函数调用期间固定为pg_catalog
,pg_temp
和您的扩展架构.这意味着所有对没有显式架构的对象的访问都只会在这些架构中进行搜索.
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.
然后,您不必担心使用@extschema@
显式限定函数中的所有内容,并且可以使用运算符而不必担心,因为search_path
同样适用于运算符. (您也可以通过模式限定运算符:OPERATOR(schema.+)
,但这显然很痛苦,而且会损害可读性.)
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.)
这篇关于如何使扩展名不可重定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!