使用psql时如何在postgres中选择架构? [英] How to select a schema in postgres when using psql?
问题描述
我有一个具有多个架构的postgres数据库。当我使用 psql
从外壳连接到数据库并运行 \dt
时,它将使用默认的连接模式是公开。有没有可以指定的标志或如何更改架构?
I have a postgres database with multiple schemas. When I connect to the database from a shell with psql
and I run \dt
it uses the default connection schema which is public. Is there a flag I can specify or how can I change the schema?
推荐答案
在PostgreSQL中,系统确定哪个表由
In PostgreSQL the system determines which table is meant by following a search path, which is a list of schemas to look in.
搜索路径中的第一个匹配表被认为是想要的一个,否则,如果存在如果没有匹配项,即使数据库中其他模式中存在匹配表名,也会引发错误。
The first matching table in the search path is taken to be the one wanted, otherwise, if there is no match a error is raised, even if matching table names exist in other schemas in the database.
要显示当前搜索路径,可以使用以下命令: / p>
To show the current search path you can use the following command:
SHOW search_path;
将新模式放入路径中,可以使用:
And to put the new schema in the path, you could use:
SET search_path TO myschema;
或者如果您想要多个模式:
Or if you want multiple schemas:
SET search_path TO myschema, public;
参考: https://www.postgresql.org/docs/current/static/ddl-schemas.html
这篇关于使用psql时如何在postgres中选择架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!