COMMENT ON
{
AGGREGATE aggregate_name ( aggregate_signature ) |
CAST (source_type AS target_type) |
COLLATION object_name |
COLUMN relation_name.column_name |
CONSTRAINT constraint_name ON table_name |
CONVERSION object_name |
DATABASE object_name |
DOMAIN object_name |
EXTENSION object_name |
EVENT TRIGGER object_name |
FOREIGN DATA WRAPPER object_name |
FOREIGN TABLE object_name |
FUNCTION function_name ( [ [ argmode ] [ argname ] argtype [, ...] ] ) |
INDEX object_name |
LARGE OBJECT large_object_oid |
MATERIALIZED VIEW object_name |
OPERATOR operator_name (left_type, right_type) |
OPERATOR CLASS object_name USING index_method |
OPERATOR FAMILY object_name USING index_method |
[ PROCEDURAL ] LANGUAGE object_name |
ROLE object_name |
RULE rule_name ON table_name |
SCHEMA object_name |
SEQUENCE object_name |
SERVER object_name |
TABLE object_name |
TABLESPACE object_name |
TEXT SEARCH CONFIGURATION object_name |
TEXT SEARCH DICTIONARY object_name |
TEXT SEARCH PARSER object_name |
TEXT SEARCH TEMPLATE object_name |
TRIGGER trigger_name ON table_name |
TYPE object_name |
VIEW object_name
} IS 'text'
where aggregate_signature is:
* |
[ argmode ] [ argname ] argtype [ , ... ] |
[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
COMMENT存储一个数据库对象的注释。
每个对象只存储一条注释,因此要修改一个注释,对同一个对象发出一条新的COMMENT命令即可。 要删除注释,在文本字符串的位置写上NULL即可。 当删除对象时,注释自动被删除掉。
对大多数对象,只有对象的所有者可以设置注释。角色没有所有者,所以COMMENT ON ROLE命令仅可以由超级用户对超级用户角色执行, 有CREATEROLE权限的角色也可以为非超级用户角色设置注释,当然超级用户可以对所有对象进行注释。
注释可以用psql程序中的\d命令检索。
其它希望提取注释的用户接口设计可以使用程序psql使用的同样的内置函数obj_description
、col_description
和shobj_description
(参见表 9-60)。
要加入注释的对象名称。表、聚合、排序规则、编码转换、域、外部表、函数、索引、操作符、操作符类、操作符系列、序列、全文搜索对象 、类型、视图,名字可以有模式修饰。 当对一个字段进行注释时,relation_name必需是针对一个表、视图、复合类型或是外部表。
类型转换的源数据类型 。
类型转换的目标数据类型 。
函数或聚合参数的模式:IN、OUT、INOUT或VARIADIC。如果省略,缺省值是IN。 请注意COMMENT实际上不会使用OUT参数, 因为只要有输入参数就可以判断函数的身份了。 因此,只要列出IN、INOUT和VARIADIC参数就足够了。
函数或聚合参数的名字。请注意COMMENT实际上并不使用参数名,因为只要有参数的数据类型就可以判断函数的身份。
函数或聚合参数的数据类型。
大对象的OID 。
操作符参数的数据类型(可以用模式修饰)。 当前置或后置操作符不存在时,可以增加NONE选项。
这个选项没有任何用处。
新的注释,以字符串文本的方式写;如果是NULL则删除注释。
目前注释浏览没有安全机制:任何连接到某数据库上的用户都可以看到所有该数据库对象的注释。 共享对象(比如数据库、角色、表空间)的注释是全局存储的,连接到任何数据库的任何用户都可以看到它们。 因此,不要在注释里存放与安全有关的敏感信息。
给表mytable加注释:
COMMENT ON TABLE mytable IS 'This is my table.';
再删除注释:
COMMENT ON TABLE mytable IS NULL;
其它一些例子:
COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance'; COMMENT ON CAST (text AS int4) IS 'Allow casts from text to int4'; COMMENT ON COLLATION "fr_CA" IS 'Canadian French'; COMMENT ON COLUMN my_table.my_column IS 'Employee ID number'; COMMENT ON CONVERSION my_conv IS 'Conversion to UTF8'; COMMENT ON CONSTRAINT bar_col_cons ON bar IS 'Constrains column col'; COMMENT ON DATABASE my_database IS 'Development Database'; COMMENT ON DOMAIN my_domain IS 'Email Address Domain'; COMMENT ON EXTENSION hstore IS 'implements the hstore data type'; COMMENT ON FOREIGN DATA WRAPPER mywrapper IS 'my foreign data wrapper'; COMMENT ON FOREIGN TABLE my_foreign_table IS 'Employee Information in other database'; COMMENT ON FUNCTION my_function (timestamp) IS 'Returns Roman Numeral'; COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee ID'; COMMENT ON LANGUAGE plpython IS 'Python support for stored procedures'; COMMENT ON LARGE OBJECT 346344 IS 'Planning document'; COMMENT ON MATERIALIZED VIEW my_matview IS 'Summary of order history'; COMMENT ON OPERATOR ^ (text, text) IS 'Performs intersection of two texts'; COMMENT ON OPERATOR - (NONE, integer) IS 'Unary minus'; COMMENT ON OPERATOR CLASS int4ops USING btree IS '4 byte integer operators for btrees'; COMMENT ON OPERATOR FAMILY integer_ops USING btree IS 'all integer operators for btrees'; COMMENT ON ROLE my_role IS 'Administration group for finance tables'; COMMENT ON RULE my_rule ON my_table IS 'Logs updates of employee records'; COMMENT ON SCHEMA my_schema IS 'Departmental data'; COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys'; COMMENT ON SERVER myserver IS 'my foreign server'; COMMENT ON TABLE my_schema.my_table IS 'Employee Information'; COMMENT ON TABLESPACE my_tablespace IS 'Tablespace for indexes'; COMMENT ON TEXT SEARCH CONFIGURATION my_config IS 'Special word filtering'; COMMENT ON TEXT SEARCH DICTIONARY swedish IS 'Snowball stemmer for Swedish language'; COMMENT ON TEXT SEARCH PARSER my_parser IS 'Splits text into words'; COMMENT ON TEXT SEARCH TEMPLATE snowball IS 'Snowball stemmer'; COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for RI'; COMMENT ON TYPE complex IS 'Complex number data type'; COMMENT ON VIEW my_view IS 'View of departmental costs';