Hao*_*Hao 5 postgresql namespaces
如果我不符合“公众”的资格。在 account_category 表上,out account_category将与 account_category 表名称发生冲突。
是否“公开”。也适用于其他 RDBMS?
CREATE OR REPLACE FUNCTION X_RAIN(x VARCHAR, OUT user_id VARCHAR, out account_category varchar, out depth int) returns setof record
AS
$$
BEGIN
return query
select uar.account_id, c.account_category, c.depth
from account_with_types_chart_of_account uar
inner join public.account_category c using(account_category_id);
END;
$$ LANGUAGE 'plpgsql';
Run Code Online (Sandbox Code Playgroud)
关于 PostgreSQL 中的 public,当未指定模式名称时,public 被定义为默认模式名称。但是,这可以在 postgresql.conf 文件中的 search_path = xxx 行中更改。要查看当前的默认架构设置,请发出以下 SQL 命令:
SHOW_ search_path;
Run Code Online (Sandbox Code Playgroud)
如果要更改打开查询会话中的默认架构路径,请发出以下 SQL 命令:
SET search_path = new_path;
Run Code Online (Sandbox Code Playgroud)
但是,在您发布的示例中,我相信您遇到的命名冲突不是模式名称,而是函数参数名称account_category 和表名称 account_category。您可以重命名参数名称以避免这种冲突。在具有许多模式的数据库中,为了清楚起见,我经常在数据库对象名称的开头显式指定 public。
关于你的第二个问题,我不认为 PostgreSQL 在公共使用方面是独一无二的,但我确实知道许多其他数据库以不同的方式执行其模式。