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

查看:86
本文介绍了永久设置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上的一个查询会话,在我关闭查询窗口后,path变量会将其自身设置回默认值.

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天全站免登陆