postgresql 使用查询工具在 pgAdmin 4 中查询时设置默认模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45714927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set deafult schema while querying in pgAdmin 4 with query tool
提问by Subin Chalil
Whenever i have to execute sql commands in pgAdmin 4
i have to append schema_name
with tables.
Eg :-
每当我必须在其中执行 sql 命令时,pgAdmin 4
我都必须附加schema_name
表。例如:-
SELECT * FROM my_schema.users //where myschema is schema name
ORDER BY id ASC
Is there any way to execute sql commands in pgAdmin 4
without schema name, by setting a default schema in advance.
有没有办法在pgAdmin 4
没有模式名称的情况下执行 sql 命令,通过提前设置默认模式。
Some thing like this
像这样的事情
SELECT * FROM programme
ORDER BY id ASC
- without specifying schema name with table.
- 不使用表指定模式名称。
Is there a way to set default schema in pgAdmin 4
for querying in sql tool?
有没有办法设置默认模式以 pgAdmin 4
在 sql 工具中查询?
回答by ?ukasz Kamiński
You can do it in 2 ways:
你可以通过两种方式做到这一点:
SET search_path = my_schema, "$user", public; -- For current session only
ALTER ROLE your_role SET search_path = my_schema, "$user", public; -- Persistent, for role
You can also set it for whole database, same way as for role.
您也可以为整个数据库设置它,与角色相同。
EDIT: Just to explain what this does - it will change where and in what order Postgres will search for objects matching object identifiers that did not get prefixed with schema name.
编辑:只是为了解释它的作用 - 它会改变 Postgres 将搜索匹配对象标识符的对象的位置和顺序,这些对象标识符没有以模式名称为前缀。