gpt4 book ai didi

postgresql - Postgresql 列出数据库中的所有表

转载 作者:行者123 更新时间:2023-11-29 14:24:15 26 4
gpt4 key购买 nike

“psql\dt information_schema”我正在编写此命令以查看所有表的列表及其询问“用户信息的密码_schema:”我应该提供哪个密码,我想我提供 postgres 作为密码。

最佳答案

您正在使用以下命令执行的操作:

psql \dt information_schema

是启动 psql 并传递名称“information_schema”作为要连接的用户名。

命令 \dt information_schema 必须在启动 psql 之后 并且看到 psql 提示后输入。

如果你想直接从命令行运行它而不等待 psql 提示符,你需要使用 -c 开关:

psql -c "\dt information_schema.*" postgres postgres

当您运行 psql --help 或查看手册时,会列出所有参数及其预期顺序:

http://www.postgresql.org/docs/current/static/app-psql.html

编辑

这是一个示例控制台 session ,向您展示了如何执行此操作:

c:\>psql postgres postgresPassword for user postgres:psql (9.0.4)Type "help" for help.postgres=# \dt information_schema.*                        List of relations       Schema       |          Name           | Type  |  Owner--------------------+-------------------------+-------+---------- information_schema | sql_features            | table | postgres information_schema | sql_implementation_info | table | postgres information_schema | sql_languages           | table | postgres information_schema | sql_packages            | table | postgres information_schema | sql_parts               | table | postgres information_schema | sql_sizing              | table | postgres information_schema | sql_sizing_profiles     | table | postgres(7 rows)postgres=# \dv information_schema.*                            List of relations       Schema       |               Name                | Type |  Owner--------------------+-----------------------------------+------+--------- information_schema | _pg_foreign_data_wrappers         | view | postgres information_schema | _pg_foreign_servers               | view | postgres information_schema | _pg_user_mappings                 | view | postgres information_schema | administrable_role_authorizations | view | postgres information_schema | applicable_roles                  | view | postgres information_schema | attributes                        | view | postgres information_schema | check_constraint_routine_usage    | view | postgres information_schema | check_constraints                 | view | postgres information_schema | column_domain_usage               | view | postgres information_schema | column_privileges                 | view | postgres information_schema | column_udt_usage                  | view | postgres information_schema | columns                           | view | postgres information_schema | constraint_column_usage           | view | postgres information_schema | constraint_table_usage            | view | postgres information_schema | data_type_privileges              | view | postgres information_schema | domain_constraints                | view | postgres information_schema | domain_udt_usage                  | view | postgres-- More  --

下面是如何在一次调用中完成:

c:\>psql -c "\dt information_schema.*" postgres postgresPassword for user postgres:                        List of relations       Schema       |          Name           | Type  |  Owner--------------------+-------------------------+-------+---------- information_schema | sql_features            | table | postgres information_schema | sql_implementation_info | table | postgres information_schema | sql_languages           | table | postgres information_schema | sql_packages            | table | postgres information_schema | sql_parts               | table | postgres information_schema | sql_sizing              | table | postgres information_schema | sql_sizing_profiles     | table | postgres(7 rows)c:\

关于postgresql - Postgresql 列出数据库中的所有表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7443976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com