Sql 安全定义器函数';中未定义公共架构;s搜索路径,但仍可访问
当我定义这样一个函数时:Sql 安全定义器函数';中未定义公共架构;s搜索路径,但仍可访问,sql,postgresql,Sql,Postgresql,当我定义这样一个函数时: 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
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")
为什么我仍然能够在公共模式中使用函数,比如trim或current_模式?是否只有在显式使用public.trim()时才有效
我创建的模式中的函数的工作方式不同。在本例中,我尝试在util模式中使用函数,而不在搜索路径中设置它:
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.
在函数之外,我的搜索路径设置如下:
select current_schemas('true');
current_schemas
------------------------------------------------------------
{pg_temp_2,pg_catalog,public,util}
查看您的
public
schema。你看到了吗?当前的模式?不,他们不在那里。读一读这个
在公共模式上:
默认情况下,[…]表(和其他对象)将自动放入
名为“public”的模式。每个新数据库都包含这样一个模式。
[…]公共模式没有什么特别之处,只是
默认情况下存在。它也可以被丢弃
那么它是如何解析当前的模式的呢
除了公共和用户创建的模式外,每个数据库还包含
pg_目录模式,其中包含系统表和所有
内置数据类型、函数和运算符。pg_目录始终是
实际上是搜索路径的一部分。如果未在中显式命名
然后,在搜索路径的
模式。这确保了内置名称始终是可查找的。
但是,您可以在搜索结束时显式放置pg_目录
如果希望用户定义的名称覆盖内置名称,请选择路径
查看一下pgu目录
(在PGAdmin的Catalogs
下),当前架构
在那里的函数列表中
内置功能TRIM是PG识别的关键字,请参见谢谢您的解释!我想我应该检查pg_目录,考虑到它是在我当前的_模式中返回的。。。把头撞在墙上的秘密。