如何使用psql命令在PostgreSQL中执行Oracle的DESCRIBE TABLE?


当前回答

您也可以使用以下查询进行检查

Select * from schema_name.table_name limit 0;

示例:我的表有两列名称和pwd。下面是截图。

*使用PG admin3

其他回答

您可以使用星号执行\d*搜索模式*,以查找与您感兴趣的搜索模式匹配的表。

Use this command 

\d table name

like 

\d queuerecords

             Table "public.queuerecords"
  Column   |            Type             | Modifiers
-----------+-----------------------------+-----------
 id        | uuid                        | not null
 endtime   | timestamp without time zone |
 payload   | text                        |
 queueid   | text                        |
 starttime | timestamp without time zone |
 status    | text                        |

即使请求了psql命令,我也会添加pg_dump命令。因为它生成了以前的MySQl用户更常见的输出。

#sudo-u postgres pg_dump--table=my_table_name--仅模式mydb

您可以使用psql斜杠命令执行此操作:

 \d myTable describe table

它也适用于其他对象:

 \d myView describe view
 \d myIndex describe index
 \d mySequence describe sequence

来源:faqs.org

除了PostgreSQL方式(\d“something”或\dt“table”或\ds“sequence”等)

SQL标准方式,如下所示:

select column_name, data_type, character_maximum_length, column_default, is_nullable
from INFORMATION_SCHEMA.COLUMNS where table_name = '<name of table>';

它受到许多db引擎的支持。