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


当前回答

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

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

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

其他回答

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

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

\dt <table> <table>

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

\d <table> <table>

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

\d+ <table> <table>

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

\d+ schema_name.table_name

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

In postgres\d用于描述表结构。

例如\d schema_name.table_name

该命令将为您提供表的基本信息,如列、类型和修饰符。

如果您想了解更多有关表格使用的信息

\d+ schema_name.table_name

这将为您提供额外的信息,如存储、统计目标和描述

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/