永久设置Postgresql模式路径

编程入门 行业动态 更新时间:2024-10-28 09:15:00
本文介绍了永久设置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;

要了解的两个重要事项:

  • 如果架构名称不简单,则需要将其用双引号引起来.
  • 设置默认模式a, b, c的顺序很重要,因为这也是在表中查找模式的顺序.因此,如果您在多个默认值中的多个模式中具有相同的表名,则不会有歧义,服务器将始终使用您为search_path指定的第一个模式中的表.
  • When a schema name is not simple, it needs to be wrapped in double quotes.
  • 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模式路径

    本文发布于:2023-10-15 11:50:32,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1494252.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:路径   模式   Postgresql

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!