©
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
COMMENT ON { TABLE object_name | COLUMN table_name.column_name | AGGREGATE agg_name (agg_type [, ...] ) | CAST (source_type AS target_type) | CONSTRAINT constraint_name ON table_name | CONVERSION object_name | DATABASE object_name | DOMAIN object_name | FUNCTION function_name ( [ [ argmode ] [ argname ] argtype [, ...] ] ) | INDEX object_name | LARGE OBJECT large_object_oid | 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 | 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'
COMMENT存储一个数据库对象的评注。
要修改一个评注,为同一个对象发出一条新的COMMENT命令即可。 每个对象只存储一条评注。要删除评注,在文本字符串的位置写上NULL即可。 当删除对象时,评注自动被删除掉。
评注可以用命令psql的
\d检索。其它希望检索评注的用户接口可以建筑在psql使用的同样的内置函数
obj_description
,col_description
,
和shobj_description
上(参见Table 9-51)。
要加入评注的对象名称。表、聚集、域、函数、索引、操作符、操作符类、操作符家庭、序列、全文搜索对象 、类型、视图,名字可以有模式修饰。
聚集函数操作的参数类型,要引用一个零参数聚集函数,可以使用*代替输入数据类型列表。
类型转换的源数据类型
类型转换的目标数据类型
函数参数的模式:IN,OUT, INOUT或者VARIADIC。 请注意COMMENT ON FUNCTION实际上不会注意OUT参数, 因为只要有输入参数就可以判断函数的身份了。因此, 只要列出IN,INOUT, 和VARIADIC参数就足够了。
函数参数的名字。请注意COMMENT ON FUNCTION实际上并不关心参数名, 因为只要有参数的数据类型就可以判断函数的身份。
如果有的话,是函数参数的数据类型(可以用模式修饰)
大对象的OID
这个字没有任何用处
新的评注,以字符串文本的方式写;如果是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 COLUMN my_table.my_column IS 'Employee ID number'; COMMENT ON CONVERSION my_conv IS 'Conversion to UTF8'; COMMENT ON DATABASE my_database IS 'Development Database'; COMMENT ON DOMAIN my_domain IS 'Email Address Domain'; 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 OPERATOR ^ (text, text) IS 'Performs intersection of two texts'; COMMENT ON OPERATOR - (NONE, text) IS 'This is a prefix operator on text'; 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 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';
SQL标准里没有COMMENT命令。