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


当前回答

当您的表不是默认模式的一部分时,您应该写:

\d+ schema_name.table_name

否则,您将得到错误消息,即“关系不存在”

其他回答

除了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引擎的支持。

这应该是解决方案:

SELECT * FROM information_schema.columns
WHERE table_schema = 'your_schema'
   AND table_name   = 'your_table'

尝试以下操作(在psql命令行工具中):

\d+ tablename

有关更多信息,请参阅手册。

您可以使用星号执行\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                        |