永久设置 Postgresql 模式路径 [英] Permanently Set Postgresql Schema Path

查看:47
本文介绍了永久设置 Postgresql 模式路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Postgres 中设置模式路径,这样我就不会每次都指定模式点表,例如schema2.table.设置架构路径:

I need to set schema path in Postgres so that I don't every time specify schema dot table e.g. schema2.table. Set schema path:

SET SCHEMA PATH a,b,c

似乎只适用于 mac 上的一个查询会话,在我关闭查询窗口后,路径变量将自身设置回默认值.

only seems to work for one query session on mac, after I close query window the path variable sets itself back to default.

如何使其永久化?

推荐答案

(如果您没有服务器的管理员权限)

(And if you have no admin access to the server)

ALTER ROLE <your_login_role> SET search_path TO a,b,c;

需要了解的两个重要事项:

  1. 当架构名称不简单时,需要用双引号括起来.
  2. 设置默认模式的顺序 a, b, c 很重要,因为这也是查找表的模式的顺序.因此,如果您在多个默认模式中具有相同的表名,则不会有歧义,服务器将始终使用您为 search_path 指定的第一个模式中的表.
  1. When a schema name is not simple, it needs to be wrapped in double quotes.
  2. The order in which you set default schemas a, b, c matters, as it is also the order in which the schemas will be looked up for tables. So if you have the same table name in more than one schema among the defaults, there will be no ambiguity, the server will always use the table from the first schema you specified for your search_path.

这篇关于永久设置 Postgresql 模式路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆