如何使扩展名可重定位?

问题描述 投票:0回答:1

我不知道如何使扩展名可重定位。问题:如何使扩展名移至另一个方案。下面,描述开始。然后是运算符,函数,方差,数学期望的创建。

create schema IF NOT EXISTS complex;

--Mathematical expectation
--creating a complex data type
create type complex.complex as (re float, im float);
--creation of complex data type with the sum of complex numbers and the amount of numbers--
create type complex.complexSumAndCount as (complexSumVar complex.complex, complexCount integer);

--Creating the function of adding complex numbers
CREATE or REPLACE function complex.complexSumFunction (sum complex.complex, complexTempVar complex.complex)
    RETURNS complex.complex as
$$
BEGIN

    IF sum is not null and complexTempVar is not null then
        sum.re := coalesce(sum.re, 0) + coalesce(complexTempVar.re, 0);
        sum.im := coalesce(sum.im, 0) + coalesce(complexTempVar.im, 0);
    end IF;

    RETURN sum;

end; $$LANGUAGE plpgSQL;
postgresql
1个回答
0
投票

[确定,发布指向github存储库的链接可能不是改善问题的推荐方法。您仍然还没有告诉我您是否实际上在尝试编写扩展程序。

我将猜测您不是,因为您似乎没有.control文件。

如果您想做的是能够写的

select '(6,44)'::complex;

而不是

select '(6,44)'::complex.complex;

然后您需要了解的是search_path

这控制了当您未明确指定架构时,将在哪些架构中搜索对象(类型,表,函数等)。

所以-您有两个选择。要运行查询时,可以将“复杂”模式添加到search_path中。或者,您可以将“复杂”类型和函数放在当前的search_path中。

您可以使用以下方法为当前交易或会话临时设置search_path:

SET search_path = public, complex;

您可以通过类似以下方式更改用户或数据库的默认值:

ALTER USER myuser SET search_path = public, complex;
ALTER USER mydatabase SET search_path = public complex;

第二个选项是将您的“复杂”代码加载到search_path中已经存在的架构中。为此,您将从script1.sql文件中删除对架构的所有引用。

create type complex as (re float, im float);
create type complexSumAndCount as (complexSumVar complex.complex, complexCount integer);
...

然后,当您加载它时,将在可在search_path中找到的第一个模式中创建类型和函数。最好将其设置为您想要的。

SET search_path = public;
\i script1.sql

或从命令行

PGOPTIONS="--search_path=public" psql -U myuser -d mydb -f script1.sql

我希望有帮助。如果不是您想要的,那恐怕您需要发布一个新问题并准确解释您要做什么。如果您想与您的问题进行更长时间的讨论,则可以尝试使用postgresql邮件列表。

© www.soinside.com 2019 - 2024. All rights reserved.