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


当前回答

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

\d+ tablename

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

其他回答

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

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

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

例如\d schema_name.table_name

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

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

\d+ schema_name.table_name

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

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                        |

描述表的最佳方式,如列、类型、列的修饰符等。

\d+ tablename or \d tablename

我为get表模式编写了以下脚本。

'CREATE TABLE ' || 'yourschema.yourtable' || E'\n(\n' ||
array_to_string(
array_agg(
'    ' || column_expr
)
, E',\n'
) || E'\n);\n'
from
(
SELECT '    ' || column_name || ' ' || data_type || 
coalesce('(' || character_maximum_length || ')', '') || 
case when is_nullable = 'YES' then ' NULL' else ' NOT NULL' end as column_expr
FROM information_schema.columns
WHERE table_schema || '.' || table_name = 'yourschema.yourtable'
ORDER BY ordinal_position
) column_list;