如何在PostgreSQL中执行等效于Oracle DESCRIBE TABLE
的命令(使用psql命令)?
#1楼
DESCRIBE TABLE
的psql等效项是\\d table
。
有关更多详细信息,请参见PostgreSQL手册的psql部分。
#2楼
您可以使用psql斜杠命令执行此操作:
\d myTable describe table
它也适用于其他对象:
\d myView describe view
\d myIndex describe index
\d mySequence describe sequence
资料来源: faqs.org
#3楼
试试看(在psql
命令行工具中):
\d+ tablename
有关更多信息,请参见手册 。
#4楼
除了PostgreSQL方式(\\ d'something'或\\ dt'table'或\\ ds'sequence'等)
SQL标准的方式,如图所示在这里 :
select column_name, data_type, character_maximum_length
from INFORMATION_SCHEMA.COLUMNS where table_name = '<name of table>';
许多数据库引擎都支持它。
#5楼
如果要从查询而不是psql获取它,则可以查询目录架构。 这是一个执行此操作的复杂查询:
SELECT
f.attnum AS number,
f.attname AS name,
f.attnum,
f.attnotnull AS notnull,
pg_catalog.format_type(f.atttypid,f.atttypmod) AS type,
CASE
WHEN p.contype = 'p' THEN 't'
ELSE 'f'
END AS primarykey,
CASE
WHEN p.contype = 'u' THEN 't'
ELSE 'f'
END AS uniquekey,
CASE
WHEN p.contype = 'f' THEN g.relname
END AS foreignkey,
CASE
WHEN p.contype = 'f' THEN p.confkey
END AS foreignkey_fieldnum,
CASE
WHEN p.contype