PostgreSQL “DESCRIBE TABLE”

2019-01-02 19:14发布

How do you perform the equivalent of Oracle's DESCRIBE TABLE in PostgreSQL (using the psql command)?

18条回答
孤独寂梦人
2楼-- · 2019-01-02 19:20

You may do a \d *search pattern * with asterisks to find tables that match the search pattern you're interested in.

查看更多
深知你不懂我心
3楼-- · 2019-01-02 19:21

You can also check using below query

Select * from schema_name.table_name limit 0;

Expmple : My table has 2 columns name and pwd. Giving screenshot below.

Adding image

*Using PG admin3

查看更多
残风、尘缘若梦
4楼-- · 2019-01-02 19:23

In addition to the PostgreSQL way (\d 'something' or \dt 'table' or \ds 'sequence' and so on)

The SQL standard way, as shown here:

select column_name, data_type, character_maximum_length
from INFORMATION_SCHEMA.COLUMNS where table_name = '<name of table>';

It's supported by many db engines.

查看更多
墨雨无痕
5楼-- · 2019-01-02 19:23

Use the following SQL statement

SELECT DATA_TYPE 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE table_name = 'tbl_name' 
AND COLUMN_NAME = 'col_name'

If you replace tbl_name and col_name, it displays data type of the particular coloumn that you looking for.

查看更多
皆成旧梦
6楼-- · 2019-01-02 19:26

Try this (in the psql command-line tool):

\d+ tablename

See the manual for more info.

查看更多
若你有天会懂
7楼-- · 2019-01-02 19:27

The psql equivalent of DESCRIBE TABLE is \d table.

See the psql portion of the PostgreSQL manual for more details.

查看更多
登录 后发表回答