COMMENT ON [ [ DATABASE | DOMAIN | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] object_name | COLUMN table_name.column_name| AGGREGATE agg_name agg_type| CONSTRAINT constraint_name ON table_name | DATABASE object_name | DOMAIN object_name | FUNCTION func_name (arg1, arg2, ...)| OPERATOR op (leftoperand_type rightoperand_type) | TRIGGER trigger_name ON table_name ] IS 'text'
COMMENT 存储一个数据库对象的评注, 这个评注可以很容易用 psql的 \dd或 \d+ 或者 \l+ 命令检索出来. 其它检索评注的用户接口可以建设在 psql 所用地同样地内部函数的基础上, 也就是 obj_description() 和 col_description().
要修改一个评注,为同一个对象发出一条新的 COMMENT 命令即可.每个对象只存储一条评注. 要删除评注,在文本字串的位置写上 NULL. 当删除对象时,评注自动被删除掉.
需要说明的是目前评注没有安全机制∶任何联接到某数据库上地用户 都可以看到所有该数据库对象地评注(尽管只有超级用户可以修改 不属于它地对象的评注).因此,不要在评注里放安全性敏感地信息.
给表mytable 加评注:
COMMENT ON mytable IS 'This is my table.';
一些例子:
COMMENT ON DATABASE my_database IS 'Development Database'; COMMENT ON DOMAIN my_domain IS 'Email Address Domain'; COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee id'; COMMENT ON RULE my_rule IS 'Logs UPDATES of employee records'; COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys'; COMMENT ON TABLE my_table IS 'Employee Information'; COMMENT ON TYPE my_type IS 'Complex Number support'; COMMENT ON VIEW my_view IS 'View of departmental costs'; COMMENT ON COLUMN my_table.my_field IS 'Employee ID number'; COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance'; COMMENT ON FUNCTION my_function (timestamp) IS 'Returns Roman Numeral'; COMMENT ON OPERATOR ^ (text, text) IS 'Performs intersection of two text'; COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for R.I.';