当然,这里并非仅仅对该表存储的是数据库中的表列做描述,而是为了处理在系统表中依然存在表膨胀的现象,如在生产环境中,通常会做删除表或者删除 **schema** 的动作,在 **PostgreSQL** 中,只要有对表或者 **schema** 的删除动作,那么就会造成该表 **pg_attribute** 的膨胀。如下: 在某个schema下创建表 postgre...
postgres=#selectrelname,rolnamefrompg_class c,pg_authid auwhererelname='testtable'andrelowner=au.oid;*relname|rolname---+---testtable|postgres (1row) pg_attribute 该系统表存储所有表(包括系统表,如pg_class)的字段信息。数据库中的每个表的每个字段在pg_attribute表中都有一行记录。 见如下应用示例:...
relnamespace 包含这个关系的名字空间(模式)的 OID,对应pg_namespace.oid relkind r = 普通表,i = 索引,S = 序列,v = 视图, c = 复合类型,s = 特殊,t = TOAST表 pg_namespace 记录了数据库的名字空间(模式) 其中比较重要的字段有: nspname 名字空间的名字 nspowner 名字空间的所有者 pg_attribute ...
pg_attribute.attname, pg_attribute.attnum, (format_type(pg_attribute.atttypid, pg_attribute.atttypmod))::character varying AS typelen, (col_description(pg_attribute.attrelid, (pg_attribute.attnum)::integer))::character varying AS comment, CASE when pg_attribute.attnotnull = 't' then 'N...
我们还可以通过以下SQL脚本获取表字段的约束信息,如主键、外键等: SELECT conname AS constraint_name, contype AS constraint_type, a.attname AS column_name FROM pg_attribute a JOIN pg_class c ON a.attrelid = c.oid JOIN pg_constraint con ON con.conrelid = c.oid AND a.attnum = ANY (con...
6、调用heap_create函数进行初始化表访问方法和创建磁盘物理文件 7、调用AddNewRelationTuple向pg_class插入一条元数据tuple 8、调用AddNewAttributeTuples向pg_attribute插入列元数据信息 9、heap_create函数调用RelationBuildLocalRelation进行初始化表访问方法
typrelid:如果是复合类型(见 typtype)那么这个字段指向 pg_class 中定义该表的行。对于自由存在的复合类型,pg_class 记录并不表示一个表,但是总需要它来查找该类型连接的 pg_attribute 记录。对于非复合类型为零。 typelem:如果不为 0 ,那么它标识 pg_type 里面的另外一行。当前类型可以当做一个产生类型为 ...
pg_type 该系统表用于记录管理所有的类型定义,比如上面的create table map_test (id int, value map);建表过程中用到的类型int以及 复合类型map都会被存储到pg_type中,而列名字id以及value则会被存储到的pg_attribute系统表中,这个后面会说。 PG 通过pg_class的对象属性描述的系统表 以及pg_type和pg_attribute...
pg_class INNER JOIN pg_namespace ON (pg_class.relnamespace = pg_namespace.oid AND lower(pg_namespace.nspname) = a_schema_name) WHERE pg_class.relname=a_table_name; IF NOT FOUND THEN RETURN; END IF; v_sql=' SELECT pg_attribute.attname AS fields_name, ...
(2 rows) /*pg_attribute中现有记录的atthasmissing并未修改*/ select attname,atthasdef,atthasmissing,attmissingval from pg_attribute where attrelid = 'tb4'::regclass and attnum > 0; attname | atthasdef | atthasmissing | attmissingval ---+---+---+--- id | f | f | value1...