SQL 如何在 postgres 模式中列出关系
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4109017/
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
How to list relations in postgres schema
提问by Joseph Mastey
I need help with a pretty basic Postgres command, but I cannot find a reference anywhere. My cluster is set up like this:
我需要一个非常基本的 Postgres 命令的帮助,但我在任何地方都找不到参考。我的集群设置如下:
database_1
\- schema_1
\- schema_2
\- relation_1
\- relation_2
\- ...
\- relation_3
\- relation_4
\- ...
I know how to list databases (\l
), and I know how to list relations in the "default" schema (\dt
). Heck, I can even list schemas (\dn
), but I cannot, for the life of me, list the relations within a schema.
我知道如何列出数据库 ( \l
),我知道如何在“默认”模式 ( \dt
) 中列出关系。哎呀,我什至可以列出模式 ( \dn
),但我一生都无法列出模式中的关系。
Halp!
呸!
Thanks, Joe
谢谢,乔
To pre-clarify, what I'm looking for is this:
为了预先澄清,我正在寻找的是:
> \c database_1
You are now connected to database_1
> \somecommand
relation_1
relation_2
>
回答by Szymon Lipiński
Try this one:
试试这个:
\dt schema_2.
回答by Mitch
I'll clarify since this is the first result of a google search.
我会澄清,因为这是谷歌搜索的第一个结果。
\dt schema_2
will not list all the relations for schema_2
.
\dt schema_2
不会列出 的所有关系schema_2
。
The correct answer is in the comments of the answer.
正确答案在答案的评论中。
\dt schema_2.*
A more thorough answer can be found here, List tables in a PostgreSQL schema
可以在此处找到更彻底的答案,列出 PostgreSQL 模式中的表
回答by eadsjr
As of PostgresQL version 11.2 I find that this performs as expected. It lists views and sequences as well, not just tables.
从 PostgresQL 11.2 版开始,我发现这按预期执行。它也列出了视图和序列,而不仅仅是表格。
\d schema_2.
\d schema_2。
If you replace schema_2 with your schema name and leave the dot it appears to work fine.
如果您将 schema_2 替换为您的架构名称并留下点,它似乎可以正常工作。
Some further command instructions are available in a psql connection via \?
在 psql 连接中通过 \?