postgresql的注释工具层面的支持并不友好,因此可采用命令的形式来进行字段、表进行添加注释。同时,也可以通过一条SQL语句来查询字段的注释和类型。
首先我们来看添加注释:
表添加注释
comment on table tb_user is ‘The user table’;
其中tb_user替换成对应的表明,单引号内的描述替换为对应表的描述即可。
字段添加注释
comment on column tb_user.id is ‘The user ID’;
其中tb_user.id指的是表tb_user的id字段,同样单引号内的内容为注释的具体信息。
查询注释
SELECT
a.attname as “字段名”,
col_description(a.attrelid,a.attnum) as “注释”,
concat_ws(’’,t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from ‘(.*)’)) as “字段类型”
FROM
pg_class as c,
pg_attribute as a,
pg_type as t
WHERE
c.relname = ‘tb_user’
and a.atttypid = t.oid
and a.attrelid = c.oid
and a.attnum>0;
在上述查询注释语句中只需要替换掉c.relname=’tb_user’中的tb_user为你要查询的表即可。此时便可查询除对应表结构的描述和字段类型信息。
使用SQL Pro工具查询时,查询效果如下:
postgresql表、字段添加注释和查询注释插图
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200711143750601.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NsYXBBbG9uZw==,size_16,color_FFFFFF,t_70)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)