如何使用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                        |

其他回答

我为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;

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

例如\d schema_name.table_name

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

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

\d+ schema_name.table_name

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

您也可以使用以下查询进行检查

Select * from schema_name.table_name limit 0;

示例:我的表有两列名称和pwd。下面是截图。

*使用PG admin3

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

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

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

 \d myTable describe table

它也适用于其他对象:

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

来源:faqs.org