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


当前回答

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

\d+ tablename

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

其他回答

1) 使用psql的PostgreSQL描述表

在psql命令行工具中,使用\d table_name或\d+table_name查找表的列信息

2) PostgreSQL使用information_schema描述表

SELECT语句查询information_schema数据库中列表的column_name、数据类型、字符最大长度;

选择列名称、数据类型、字符最大长度来自INFORMATION_SCHEMA.COLUMNS,其中table_name=“tablename”;

有关详细信息https://www.postgresqltutorial.com/postgresql-describe-table/

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

\d+ tablename

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

除了已经找到的命令行\d+<table_name>之外,还可以使用info_schema.columns使用信息模式查找列数据

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

下面的命令可以简单地描述多个表

\dt <table> <table>

下面的命令可以详细描述多个表:

\d <table> <table>

下面的命令可以更详细地描述多个表:

\d+ <table> <table>

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

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

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