获取当前 Postgres 数据库模式名称

3

我想获取当前连接架构名称,我发现 'show search_path' 返回所需结果,但我需要在查询中使用此结果。

如何在 Postgres 查询中使用 "show search_path"?

if not (SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE 
  table_name = 'customer' and table_schema = **show search_path** )) then
do something ....
end

I need to use table_schema = show search_path


3
类似于 SELECT CURRENT_SCHEMA吗? - Jim Jones
2个回答

8
使用current_schema函数。它会返回在search_path路径中存在的第一个模式,也就是未经限定创建表时的模式。

1
SELECT EXISTS (
  SELECT 1 FROM information_schema.tables
  WHERE table_name = 'project_customer_scheme'
  AND table_schema = (
    SELECT setting FROM pg_settings WHERE name = 'search_path'
)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接