2 doc/src/sgml/ref/comment.sgml
3 PostgreSQL documentation
6 <refentry id="SQL-COMMENT">
8 <refentrytitle>COMMENT</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements</refmiscinfo>
14 <refname>COMMENT</refname>
15 <refpurpose>define or change the comment of an object</refpurpose>
18 <indexterm zone="sql-comment">
19 <primary>COMMENT</primary>
26 AGGREGATE <replaceable class="PARAMETER">agg_name</replaceable> (<replaceable class="PARAMETER">agg_type</replaceable> [, ...] ) |
27 CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) |
28 COLLATION <replaceable class="PARAMETER">object_name</replaceable> |
29 COLUMN <replaceable class="PARAMETER">relation_name</replaceable>.<replaceable class="PARAMETER">column_name</replaceable> |
30 CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> ON <replaceable class="PARAMETER">table_name</replaceable> |
31 CONVERSION <replaceable class="PARAMETER">object_name</replaceable> |
32 DATABASE <replaceable class="PARAMETER">object_name</replaceable> |
33 DOMAIN <replaceable class="PARAMETER">object_name</replaceable> |
34 EXTENSION <replaceable class="PARAMETER">object_name</replaceable> |
35 FOREIGN DATA WRAPPER <replaceable class="PARAMETER">object_name</replaceable> |
36 FOREIGN TABLE <replaceable class="PARAMETER">object_name</replaceable> |
37 FUNCTION <replaceable class="PARAMETER">function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) |
38 INDEX <replaceable class="PARAMETER">object_name</replaceable> |
39 LARGE OBJECT <replaceable class="PARAMETER">large_object_oid</replaceable> |
40 OPERATOR <replaceable class="PARAMETER">operator_name</replaceable> (<replaceable class="PARAMETER">left_type</replaceable>, <replaceable class="PARAMETER">right_type</replaceable>) |
41 OPERATOR CLASS <replaceable class="PARAMETER">object_name</replaceable> USING <replaceable class="parameter">index_method</replaceable> |
42 OPERATOR FAMILY <replaceable class="PARAMETER">object_name</replaceable> USING <replaceable class="parameter">index_method</replaceable> |
43 [ PROCEDURAL ] LANGUAGE <replaceable class="PARAMETER">object_name</replaceable> |
44 ROLE <replaceable class="PARAMETER">object_name</replaceable> |
45 RULE <replaceable class="PARAMETER">rule_name</replaceable> ON <replaceable class="PARAMETER">table_name</replaceable> |
46 SCHEMA <replaceable class="PARAMETER">object_name</replaceable> |
47 SEQUENCE <replaceable class="PARAMETER">object_name</replaceable> |
48 SERVER <replaceable class="PARAMETER">object_name</replaceable> |
49 TABLE <replaceable class="PARAMETER">object_name</replaceable> |
50 TABLESPACE <replaceable class="PARAMETER">object_name</replaceable> |
51 TEXT SEARCH CONFIGURATION <replaceable class="PARAMETER">object_name</replaceable> |
52 TEXT SEARCH DICTIONARY <replaceable class="PARAMETER">object_name</replaceable> |
53 TEXT SEARCH PARSER <replaceable class="PARAMETER">object_name</replaceable> |
54 TEXT SEARCH TEMPLATE <replaceable class="PARAMETER">object_name</replaceable> |
55 TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> ON <replaceable class="PARAMETER">table_name</replaceable> |
56 TYPE <replaceable class="PARAMETER">object_name</replaceable> |
57 VIEW <replaceable class="PARAMETER">object_name</replaceable>
58 } IS '<replaceable class="PARAMETER">text</replaceable>'
63 <title>Description</title>
66 <command>COMMENT</command> stores a comment about a database object.
70 Only one comment string is stored for each object, so to modify a comment,
71 issue a new <command>COMMENT</> command for the same object. To remove a
72 comment, write <literal>NULL</literal> in place of the text string.
73 Comments are automatically dropped when their object is dropped.
77 For most kinds of object, only the object's owner can set the comment.
78 Roles don't have owners, so the rule for <literal>COMMENT ON ROLE</> is
79 that you must be superuser to comment on a superuser role, or have the
80 <literal>CREATEROLE</> privilege to comment on non-superuser roles.
81 Of course, a superuser can comment on anything.
85 Comments can be viewed using <application>psql</application>'s
86 <command>\d</command> family of commands.
87 Other user interfaces to retrieve comments can be built atop
88 the same built-in functions that <application>psql</application> uses, namely
89 <function>obj_description</>, <function>col_description</>,
90 and <function>shobj_description</>
91 (see <xref linkend="functions-info-comment-table">).
96 <title>Parameters</title>
100 <term><replaceable class="parameter">object_name</replaceable></term>
101 <term><replaceable class="parameter">relation_name</replaceable>.<replaceable>column_name</replaceable></term>
102 <term><replaceable class="parameter">agg_name</replaceable></term>
103 <term><replaceable class="parameter">constraint_name</replaceable></term>
104 <term><replaceable class="parameter">function_name</replaceable></term>
105 <term><replaceable class="parameter">operator_name</replaceable></term>
106 <term><replaceable class="parameter">rule_name</replaceable></term>
107 <term><replaceable class="parameter">trigger_name</replaceable></term>
110 The name of the object to be commented. Names of tables,
111 aggregates, collations, conversions, domains, foreign tables, functions,
112 indexes, operators, operator classes, operator families, sequences,
113 text search objects, types, and views can be schema-qualified.
114 When commenting on a column,
115 <replaceable class="parameter">relation_name</replaceable> must refer
116 to a table, view, composite type, or foreign table.
122 <term><replaceable class="parameter">agg_type</replaceable></term>
125 An input data type on which the aggregate function operates.
126 To reference a zero-argument aggregate function, write <literal>*</>
127 in place of the list of input data types.
133 <term><replaceable>source_type</replaceable></term>
136 The name of the source data type of the cast.
142 <term><replaceable>target_type</replaceable></term>
145 The name of the target data type of the cast.
151 <term><replaceable class="parameter">argmode</replaceable></term>
154 The mode of a function argument: <literal>IN</>, <literal>OUT</>,
155 <literal>INOUT</>, or <literal>VARIADIC</>.
156 If omitted, the default is <literal>IN</>.
157 Note that <command>COMMENT ON FUNCTION</command> does not actually pay
158 any attention to <literal>OUT</> arguments, since only the input
159 arguments are needed to determine the function's identity.
160 So it is sufficient to list the <literal>IN</>, <literal>INOUT</>,
161 and <literal>VARIADIC</> arguments.
167 <term><replaceable class="parameter">argname</replaceable></term>
170 The name of a function argument.
171 Note that <command>COMMENT ON FUNCTION</command> does not actually pay
172 any attention to argument names, since only the argument data
173 types are needed to determine the function's identity.
179 <term><replaceable class="parameter">argtype</replaceable></term>
182 The data type(s) of the function's arguments (optionally
183 schema-qualified), if any.
189 <term><replaceable class="parameter">large_object_oid</replaceable></term>
192 The OID of the large object.
198 <term><replaceable class="parameter">left_type</replaceable></term>
199 <term><replaceable class="parameter">right_type</replaceable></term>
202 The data type(s) of the operator's arguments (optionally
203 schema-qualified). Write <literal>NONE</> for the missing argument
204 of a prefix or postfix operator.
210 <term><literal>PROCEDURAL</literal></term>
213 This is a noise word.
219 <term><replaceable class="parameter">text</replaceable></term>
222 The new comment, written as a string literal; or <literal>NULL</>
235 There is presently no security mechanism for viewing comments: any user
236 connected to a database can see all the comments for objects in
237 that database. For shared objects such as
238 databases, roles, and tablespaces, comments are stored globally so any
239 user connected to any database in the cluster can see all the comments
240 for shared objects. Therefore, don't put security-critical
241 information in comments.
246 <title>Examples</title>
249 Attach a comment to the table <literal>mytable</literal>:
252 COMMENT ON TABLE mytable IS 'This is my table.';
258 COMMENT ON TABLE mytable IS NULL;
266 COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance';
267 COMMENT ON CAST (text AS int4) IS 'Allow casts from text to int4';
268 COMMENT ON COLLATION "fr_CA" IS 'Canadian French';
269 COMMENT ON COLUMN my_table.my_column IS 'Employee ID number';
270 COMMENT ON CONVERSION my_conv IS 'Conversion to UTF8';
271 COMMENT ON CONSTRAINT bar_col_cons ON bar IS 'Constrains column col';
272 COMMENT ON DATABASE my_database IS 'Development Database';
273 COMMENT ON DOMAIN my_domain IS 'Email Address Domain';
274 COMMENT ON EXTENSION hstore IS 'implements the hstore data type';
275 COMMENT ON FOREIGN DATA WRAPPER mywrapper IS 'my foreign data wrapper';
276 COMMENT ON FOREIGN TABLE my_foreign_table IS 'Employee Information in other database';
277 COMMENT ON FUNCTION my_function (timestamp) IS 'Returns Roman Numeral';
278 COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee ID';
279 COMMENT ON LANGUAGE plpython IS 'Python support for stored procedures';
280 COMMENT ON LARGE OBJECT 346344 IS 'Planning document';
281 COMMENT ON OPERATOR ^ (text, text) IS 'Performs intersection of two texts';
282 COMMENT ON OPERATOR - (NONE, integer) IS 'Unary minus';
283 COMMENT ON OPERATOR CLASS int4ops USING btree IS '4 byte integer operators for btrees';
284 COMMENT ON OPERATOR FAMILY integer_ops USING btree IS 'all integer operators for btrees';
285 COMMENT ON ROLE my_role IS 'Administration group for finance tables';
286 COMMENT ON RULE my_rule ON my_table IS 'Logs updates of employee records';
287 COMMENT ON SCHEMA my_schema IS 'Departmental data';
288 COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys';
289 COMMENT ON SERVER myserver IS 'my foreign server';
290 COMMENT ON TABLE my_schema.my_table IS 'Employee Information';
291 COMMENT ON TABLESPACE my_tablespace IS 'Tablespace for indexes';
292 COMMENT ON TEXT SEARCH CONFIGURATION my_config IS 'Special word filtering';
293 COMMENT ON TEXT SEARCH DICTIONARY swedish IS 'Snowball stemmer for swedish language';
294 COMMENT ON TEXT SEARCH PARSER my_parser IS 'Splits text into words';
295 COMMENT ON TEXT SEARCH TEMPLATE snowball IS 'Snowball stemmer';
296 COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for RI';
297 COMMENT ON TYPE complex IS 'Complex number data type';
298 COMMENT ON VIEW my_view IS 'View of departmental costs';
299 </programlisting></para>
303 <title>Compatibility</title>
306 There is no <command>COMMENT</command> command in the SQL standard.