Sql postgres本地模式限定符

Sql postgres本地模式限定符,sql,postgresql,Sql,Postgresql,我使用postgres模式对视图和函数进行分组,并将它们的多个版本保存在一个数据库中(有时需要向后兼容),因为同一个函数在不同的模式中有多个版本,我不能简单地按名称引用它,但需要编写完整的限定名“schema.funcname”访问它 当从schemaA中的另一个函数引用schemaA中的函数时,我必须始终编写schemaA.funcname。当我以后重命名模式时,这会让我感到很不舒服-是否有一个限定符指示可以使用同一模式中的函数?也许像java中的“this”限定符 希望它能理解我的意思 th

我使用postgres模式对视图和函数进行分组,并将它们的多个版本保存在一个数据库中(有时需要向后兼容),因为同一个函数在不同的模式中有多个版本,我不能简单地按名称引用它,但需要编写完整的限定名“schema.funcname”访问它

当从schemaA中的另一个函数引用schemaA中的函数时,我必须始终编写schemaA.funcname。当我以后重命名模式时,这会让我感到很不舒服-是否有一个限定符指示可以使用同一模式中的函数?也许像java中的“this”限定符

希望它能理解我的意思

thx

您可以使用更改当前会话的搜索路径:

create schema test1;
create schema test2;

create function test1.f() returns int as $body$ begin return 1; end; $body$ language plpgsql;
create function test2.f() returns int as $body$ begin return 2; end; $body$ language plpgsql;

set schema 'test1';
select f();

set schema 'test2';
select f();
您还可以向函数定义中添加:

create or replace function test1.x() returns int as $body$ begin return 1; end; $body$ language plpgsql;
create or replace function test1.f() returns int as $body$ begin return x(); end; $body$ language plpgsql set search_path = 'test1';

create or replace function test2.x() returns int as $body$ begin return 2; end; $body$ language plpgsql;
create or replace function test2.f() returns int as $body$ begin return x(); end; $body$ language plpgsql set search_path = 'test2';

select test1.f();

select test2.f();

答案是thx——我知道集合模式,但这不是我想要做的,因为它会影响整个会话。然后,从test1中的函数调用f将调用与从test2中的函数调用f相同的函数。我希望函数test1调用test1.f(),test2中的函数调用test2.f()。您还可以将
search\u path
添加到函数定义中,请参阅我更新的答案。这是你需要的吗?如果没有,那就是我没有主意了。在某种程度上,这并不完全是我想要的,但它可能是有用的,我会考虑一下。无论如何,谢谢你的提示