当我定义一个函数像这样:公共架构,则不在安全定义器功能的SEARCH_PATH定义,但它仍然是可以访问
create or replace function test_func_a()
returns table(search_path name[], public_func_result text) as $$
select current_schemas('true'), trim(' does it work ');
$$ language sql stable security definer set search_path = pg_temp;
select test_func_a();
test_func_a
-------------------------------------------
("{pg_catalog,pg_temp_2}","does it work")
为什么我仍然可以使用的功能在公共模式如修剪或current_schemas为此事?不应该只有在明确使用public.trim()时才有效?
我创建的模式中的函数不能以相同的方式工作。在这个例子中,我尝试使用在UTIL模式的功能,而不在SEARCH_PATH设置它:
create or replace function test_func_b()
returns table(search_path name[], public_func_result text) as $$
select current_schemas('true'), trim_whitespace(' does it work ');
$$ language sql stable security definer set search_path = pg_temp;
ERROR: function trim_whitespace(unknown) does not exist
LINE 3: select current_schemas('true'), trim_whitespace(' does it ...
^
HINT: No function matches the given name and argument types. You might need
to add explicit type casts.
之外的功能,我SEARCH_PATH设置为这样:
select current_schemas('true');
current_schemas
------------------------------------------------------------
{pg_temp_2,pg_catalog,public,util}
谢谢你的解释!我想我应该检查一下pg_catalog,考虑到它正在我的current_schemas中被返回......将头撞到墙上的奥秘。 – dusterdb88