【发布时间】:2016-07-12 13:12:21
【问题描述】:
在 postgres 中,pg_temp 模式默认位于搜索路径上。
正如 Tom Lane 所解释的那样,pg_temp 架构中的 here 函数默认情况下是不可调用的,因为安全原因没有前缀。
但是他指出,为了在不带前缀的情况下调用 pg_temp 架构中的函数,您必须将临时架构显式添加到搜索路径中。不幸的是,从 postgresql 9.4 开始,这似乎不再起作用了。
set search_path to pg_temp,public;
-- create function in the temp schema
create function test_fun() returns int as $$ select 1; $$ language sql;
-- results in "function test_fun() does not exist"
select test_fun();
-- works perfectly
select pg_temp.test_fun();
有没有什么方法可以调用 pg_temp 模式中的函数而不加前缀?
这对于开发新功能非常方便。
【问题讨论】:
-
只是一个提示,我正在使用我自己的架构
temp,它不时被清空。 -
我也想过这个。这就引出了另一个问题。 pg_temp 模式的性能是否优于常规模式?
-
即便如此,差异也不是很重要,尤其是在测试期间。