说明
PostgreSQL 一览表 pg_attribute存储关于表列的信息,数据库中每张表中的行都会对应在该系统表 pg_attribute 中。既然存储的是数据库中表字段相关的信息,那么对表所做的修改都会通过该表记录。如创建表指定的列,修改表,修改表的数据类型等等。
创建自定义函数查看某张表的信息
postgres=# CREATE OR REPLACE FUNCTION f_get_table_column_info(varchar,varchar)
postgres-# RETURNS TABLE
postgres-# (
postgres(# 模式名称 varchar,
postgres(# 表名称 varchar,
postgres(# 表所属表空间 varchar,
postgres(# 表对应列名称 varchar,
postgres(# 表对应列数据类型oid oid,
postgres(# 表对应列顺序编号 integer,
postgres(# 标识列 text
postgres(# )
postgres-# AS
postgres-# $FUNCTION$
postgres$# SELECT a.schemaname,
postgres$# a.tablename,
postgres$# a.tablespace,
postgres$# d.attname,
postgres$# d.atttypid,
postgres$# d.attnum,
postgres$# d.attidentity
postgres$# FROM pg_tables a,
postgres$# pg_class b,
postgres$# pg_attribute d
postgres$# WHERE b.oid = d.attrelid
postgres$# AND a.tablename = b.relname
postgres$# AND d.attrelid = $1::regclass
postgres$# AND a.schemaname = $2
postgres$# AND a.schemaname !~ 'pg_catalog|information_schema'
postgres$# AND d.attname !~ 'xmin|xmax|cmax|cmin|ctid|tableoid';
postgres$# $FUNCTION$
postgres