列出postgresql information_schema中的所有表

发布于 2024-08-21 14:15:08 字数 137 浏览 12 评论 0原文

列出 PostgreSQL information_schema 中所有表的最佳方法是什么?

澄清一下:我正在使用一个空数据库(我没有添加任何自己的表),但我想查看 information_schema 结构中的每个表。

What is the best way to list all of the tables within PostgreSQL's information_schema?

To clarify: I am working with an empty DB (I have not added any of my own tables), but I want to see every table in the information_schema structure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

枯叶蝶 2024-08-28 14:15:08

您应该能够运行 select * from information_schema.tables 来获取由 Postgres 为特定数据库管理的每个表的列表。

您还可以添加 where table_schema = 'information_schema' 以仅查看信息架构中的表。

You should be able to just run select * from information_schema.tables to get a listing of every table being managed by Postgres for a particular database.

You can also add a where table_schema = 'information_schema' to see just the tables in the information schema.

靑春怀旧 2024-08-28 14:15:08

要列出您的表,请使用:

SELECT table_name FROM information_schema.tables WHERE table_schema='public'

它将仅列出您创建的表。

For listing your tables use:

SELECT table_name FROM information_schema.tables WHERE table_schema='public'

It will only list tables that you create.

妖妓 2024-08-28 14:15:08
\dt information_schema.

从 psql 内部,应该没问题。

\dt information_schema.

from within psql, should be fine.

放赐 2024-08-28 14:15:08

"\z" 命令 也是在交互式 psql 会话中列出表的好方法。

例如。

# psql -d mcdb -U admin -p 5555
mcdb=# /z
                           Access privileges for database "mcdb"
 Schema |              Name              |   Type   |           Access privileges
--------+--------------------------------+----------+---------------------------------------
 public | activities                     | table    |
 public | activities_id_seq              | sequence |
 public | activities_users_mapping       | table    |
[..]
 public | v_schedules_2                  | view     | {admin=arwdxt/admin,viewuser=r/admin}
 public | v_systems                      | view     |
 public | vapp_backups                   | table    |
 public | vm_client                      | table    |
 public | vm_datastore                   | table    |
 public | vmentity_hle_map               | table    |
(148 rows)

The "\z" COMMAND is also a good way to list tables when inside the interactive psql session.

eg.

# psql -d mcdb -U admin -p 5555
mcdb=# /z
                           Access privileges for database "mcdb"
 Schema |              Name              |   Type   |           Access privileges
--------+--------------------------------+----------+---------------------------------------
 public | activities                     | table    |
 public | activities_id_seq              | sequence |
 public | activities_users_mapping       | table    |
[..]
 public | v_schedules_2                  | view     | {admin=arwdxt/admin,viewuser=r/admin}
 public | v_systems                      | view     |
 public | vapp_backups                   | table    |
 public | vm_client                      | table    |
 public | vm_datastore                   | table    |
 public | vmentity_hle_map               | table    |
(148 rows)
2024-08-28 14:15:08

1.从information_schema.tables中获取所有表和视图,包括information_schema和pg_catalog的表和视图。

select * from information_schema.tables

2.获取属于特定模式的表和视图

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog')

3.仅获取表(几乎\dt)

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog') and
    table_type = 'BASE TABLE'

1.get all tables and views from information_schema.tables, include those of information_schema and pg_catalog.

select * from information_schema.tables

2.get tables and views belong certain schema

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog')

3.get tables only(almost \dt)

select * from information_schema.tables
    where table_schema not in ('information_schema', 'pg_catalog') and
    table_type = 'BASE TABLE'
倾听心声的旋律 2024-08-28 14:15:08

您还可以使用

select * from pg_tables where schemaname = 'information_schema'

一般情况下 pg* 表允许您查看数据库中的所有内容,而不受您的权限限制(当然,如果您有权访问表)。

You may use also

select * from pg_tables where schemaname = 'information_schema'

In generall pg* tables allow you to see everything in the db, not constrained to your permissions (if you have access to the tables of course).

我们的影子 2024-08-28 14:15:08

对于 postgresql 中的私有模式 'xxx'

SELECT table_name FROM information_schema.tables 
 WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'

如果没有 table_type = 'BASE TABLE' ,您将列出表和视图

For private schema 'xxx' in postgresql :

SELECT table_name FROM information_schema.tables 
 WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'

Without table_type = 'BASE TABLE' , you will list tables and views

青朷 2024-08-28 14:15:08

如果您想要快速而肮脏的单行查询:

select * from information_schema.tables

您可以直接在查询工具中运行它,而无需打开 psql。

(其他帖子建议更好的更具体的信息模式查询,但作为新手,我发现这个单行查询可以帮助我掌握表格)

If you want a quick and dirty one-liner query:

select * from information_schema.tables

You can run it directly in the Query tool without having to open psql.

(Other posts suggest nice more specific information_schema queries but as a newby, I am finding this one-liner query helps me get to grips with the table)

我的鱼塘能养鲲 2024-08-28 14:15:08
select * from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE'

只得到你的桌子

select * from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE'

to get your tables only

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文