您可以使用set schema
改變搜索路徑當前會話:
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();
您還可以添加search_path
到函數的定義:
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() – user3347114
您還可以將'search_path'添加到函數定義中,查看我的更新答案。這是你需要的嗎?如果不是,那我就沒有想法。 –
在某種程度上 - 它不是我正在尋找的,但它可能是有用的,我會考慮它。無論如何感謝提示 – user3347114