PostgreSQL11 MYSQL_postgresql11 查看表结构和系统视图

本文介绍了如何在PostgreSQL11中查看表结构和系统视图。通过示例展示了使用SQL语句和内置命令`d`来检查表格详细信息,以及列出与`pg_last`相关的系统函数。

postgres=# select * from pg_tables where tablename='t';

schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity

------------+-----------+------------+------------+------------+----------+-------------+-------------

public | t | postgres | | t | f | f | f

(1 row)

postgres-# \d t

Table "public.t"

Column | Type | Collation | Nullable | Default

--------+-----------------------+-----------+----------+---------

id | integer | | not null |

name | character varying(20) | | |

Indexes:

"t_pkey" PRIMARY KEY, btree (id)

sql语句查看表结构

SELECT A

.attnum,

A.attname AS field,

T.typname AS TYPE,

A.attlen AS LENGTH,

A.atttypmod AS lengthvar,

A.attnotnull AS NOTNULL,

b.description AS COMMENT

FROM

pg_class C,

pg_attribute

A LEFT OUTER JOIN pg_description b ON A.attrelid = b.objoid

AND A.attnum = b.objsubid,

pg_type T

WHERE

C.relname = 't'

AND A.attnum > 0

AND A.attrelid = C.oid

AND A.atttypid = T.oid

ORDER BY

A.attnum;

查看系统视图

postgres-# \df pg_last*

List of functions

Schema | Name | Result data type | Argument data types | Type

------------+-------------------------------+--------------------------+-------------------------------------------------------+------

pg_catalog | pg_last_committed_xact | record | OUT xid xid, OUT "timestamp" timestamp with time zone | func

pg_catalog | pg_last_wal_receive_lsn | pg_lsn | | func

pg_catalog | pg_last_wal_replay_lsn | pg_lsn | | func

pg_catalog | pg_last_xact_replay_timestamp | timestamp with time zone | | func

(4 rows)

系统视图 官方链接

https://www.postgresql.org/docs/current/catalogs.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值