作者:瀚高PG实验室 (Highgo PG Lab)
该系统表主要存储字段缺省值,字段中的主要信息存放在pg_attribute系统表中。注意:只有明确声明了缺省值的字段在该表中才会有记录。
| 名字 | 类型 | 引用 | 描述 |
| adrelid | oid | pg_class.oid | 这个字段所属的表 |
| adnum | int2 | pg_attribute.attnum | 字段编号,其规则等同于pg_attribute.attnum |
| adbin | text | 字段缺省值的内部表现形式。 | |
| adsrc | text | 缺省值的人可读的表现形式。 |
见如下应用示例:
#查看指定表有哪些字段存在缺省值,同时显示出字段名和缺省值的定义方式
postgres=# CREATE TABLE testtable2 (i integer DEFAULT 100);
CREATE TABLE
postgres=# SELECT c.relname, a.attname, ad.adnum, ad.adsrc FROM pg_class c, pg_attribute a, pg_attrdef ad WHERE relname = 'testtable2' AND ad.adrelid = c.oid AND adnum = a.attnum AND attrelid = c.oid;
relname | attname | adnum | adsrc
-------------+----------+---------+-------
testtable2 | i | 1 | 100
(1 row)
postgres=# CREATE TABLE testtable2 (i integer DEFAULT 100);
CREATE TABLE
postgres=# SELECT c.relname, a.attname, ad.adnum, ad.adsrc FROM pg_class c, pg_attribute a, pg_attrdef ad WHERE relname = 'testtable2' AND ad.adrelid = c.oid AND adnum = a.attnum AND attrelid = c.oid;
relname | attname | adnum | adsrc
-------------+----------+---------+-------
testtable2 | i | 1 | 100
(1 row)
本文介绍了PostgreSQL中用于管理字段缺省值的系统表pg_attrdef。详细解释了该表的结构及其字段含义,并通过实例展示了如何查询指定表中带有缺省值的字段。
1444

被折叠的 条评论
为什么被折叠?



