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


当前回答

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                        |

其他回答

这应该是解决方案:

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

与DESCRIBE TABLE等效的psql是\d TABLE。

有关详细信息,请参阅PostgreSQL手册的psql部分。

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

\d+ schema_name.table_name

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

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

 \d myTable describe table

它也适用于其他对象:

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

来源:faqs.org

这个问题的变体(如其他答案中所解释的)对我很有用。

SELECT
 COLUMN_NAME
FROM
 information_schema.COLUMNS
WHERE
 TABLE_NAME = 'city';

详细描述如下:http://www.postgresqltutorial.com/postgresql-describe-table/