1<!--
2doc/src/sgml/ref/comment.sgml
3PostgreSQL documentation
4-->
5
6<refentry id="sql-comment">
7 <indexterm zone="sql-comment">
8  <primary>COMMENT</primary>
9 </indexterm>
10
11 <refmeta>
12  <refentrytitle>COMMENT</refentrytitle>
13  <manvolnum>7</manvolnum>
14  <refmiscinfo>SQL - Language Statements</refmiscinfo>
15 </refmeta>
16
17 <refnamediv>
18  <refname>COMMENT</refname>
19  <refpurpose>define or change the comment of an object</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23<synopsis>
24COMMENT ON
25{
26  ACCESS METHOD <replaceable class="parameter">object_name</replaceable> |
27  AGGREGATE <replaceable class="parameter">aggregate_name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) |
28  CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) |
29  COLLATION <replaceable class="parameter">object_name</replaceable> |
30  COLUMN <replaceable class="parameter">relation_name</replaceable>.<replaceable class="parameter">column_name</replaceable> |
31  CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ON <replaceable class="parameter">table_name</replaceable> |
32  CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ON DOMAIN <replaceable class="parameter">domain_name</replaceable> |
33  CONVERSION <replaceable class="parameter">object_name</replaceable> |
34  DATABASE <replaceable class="parameter">object_name</replaceable> |
35  DOMAIN <replaceable class="parameter">object_name</replaceable> |
36  EXTENSION <replaceable class="parameter">object_name</replaceable> |
37  EVENT TRIGGER <replaceable class="parameter">object_name</replaceable> |
38  FOREIGN DATA WRAPPER <replaceable class="parameter">object_name</replaceable> |
39  FOREIGN TABLE <replaceable class="parameter">object_name</replaceable> |
40  FUNCTION <replaceable class="parameter">function_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
41  INDEX <replaceable class="parameter">object_name</replaceable> |
42  LARGE OBJECT <replaceable class="parameter">large_object_oid</replaceable> |
43  MATERIALIZED VIEW <replaceable class="parameter">object_name</replaceable> |
44  OPERATOR <replaceable class="parameter">operator_name</replaceable> (<replaceable class="parameter">left_type</replaceable>, <replaceable class="parameter">right_type</replaceable>) |
45  OPERATOR CLASS <replaceable class="parameter">object_name</replaceable> USING <replaceable class="parameter">index_method</replaceable> |
46  OPERATOR FAMILY <replaceable class="parameter">object_name</replaceable> USING <replaceable class="parameter">index_method</replaceable> |
47  POLICY <replaceable class="parameter">policy_name</replaceable> ON <replaceable class="parameter">table_name</replaceable> |
48  [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">object_name</replaceable> |
49  PROCEDURE <replaceable class="parameter">procedure_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
50  PUBLICATION <replaceable class="parameter">object_name</replaceable> |
51  ROLE <replaceable class="parameter">object_name</replaceable> |
52  ROUTINE <replaceable class="parameter">routine_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
53  RULE <replaceable class="parameter">rule_name</replaceable> ON <replaceable class="parameter">table_name</replaceable> |
54  SCHEMA <replaceable class="parameter">object_name</replaceable> |
55  SEQUENCE <replaceable class="parameter">object_name</replaceable> |
56  SERVER <replaceable class="parameter">object_name</replaceable> |
57  STATISTICS <replaceable class="parameter">object_name</replaceable> |
58  SUBSCRIPTION <replaceable class="parameter">object_name</replaceable> |
59  TABLE <replaceable class="parameter">object_name</replaceable> |
60  TABLESPACE <replaceable class="parameter">object_name</replaceable> |
61  TEXT SEARCH CONFIGURATION <replaceable class="parameter">object_name</replaceable> |
62  TEXT SEARCH DICTIONARY <replaceable class="parameter">object_name</replaceable> |
63  TEXT SEARCH PARSER <replaceable class="parameter">object_name</replaceable> |
64  TEXT SEARCH TEMPLATE <replaceable class="parameter">object_name</replaceable> |
65  TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAGE <replaceable>lang_name</replaceable> |
66  TRIGGER <replaceable class="parameter">trigger_name</replaceable> ON <replaceable class="parameter">table_name</replaceable> |
67  TYPE <replaceable class="parameter">object_name</replaceable> |
68  VIEW <replaceable class="parameter">object_name</replaceable>
69} IS '<replaceable class="parameter">text</replaceable>'
70
71<phrase>where <replaceable>aggregate_signature</replaceable> is:</phrase>
72
73* |
74[ <replaceable>argmode</replaceable> ] [ <replaceable>argname</replaceable> ] <replaceable>argtype</replaceable> [ , ... ] |
75[ [ <replaceable>argmode</replaceable> ] [ <replaceable>argname</replaceable> ] <replaceable>argtype</replaceable> [ , ... ] ] ORDER BY [ <replaceable>argmode</replaceable> ] [ <replaceable>argname</replaceable> ] <replaceable>argtype</replaceable> [ , ... ]
76</synopsis>
77 </refsynopsisdiv>
78
79 <refsect1>
80  <title>Description</title>
81
82  <para>
83   <command>COMMENT</command> stores a comment about a database object.
84  </para>
85
86  <para>
87   Only one comment string is stored for each object, so to modify a comment,
88   issue a new <command>COMMENT</command> command for the same object.  To remove a
89   comment, write <literal>NULL</literal> in place of the text string.
90   Comments are automatically dropped when their object is dropped.
91  </para>
92
93  <para>
94   For most kinds of object, only the object's owner can set the comment.
95   Roles don't have owners, so the rule for <literal>COMMENT ON ROLE</literal> is
96   that you must be superuser to comment on a superuser role, or have the
97   <literal>CREATEROLE</literal> privilege to comment on non-superuser roles.
98   Likewise, access methods don't have owners either; you must be superuser
99   to comment on an access method.
100   Of course, a superuser can comment on anything.
101  </para>
102
103  <para>
104    Comments can be viewed using <application>psql</application>'s
105    <command>\d</command> family of commands.
106    Other user interfaces to retrieve comments can be built atop
107    the same built-in functions that <application>psql</application> uses, namely
108    <function>obj_description</function>, <function>col_description</function>,
109    and <function>shobj_description</function>
110    (see <xref linkend="functions-info-comment-table"/>).
111  </para>
112 </refsect1>
113
114 <refsect1>
115  <title>Parameters</title>
116
117  <variablelist>
118   <varlistentry>
119    <term><replaceable class="parameter">object_name</replaceable></term>
120    <term><replaceable class="parameter">relation_name</replaceable>.<replaceable>column_name</replaceable></term>
121    <term><replaceable class="parameter">aggregate_name</replaceable></term>
122    <term><replaceable class="parameter">constraint_name</replaceable></term>
123    <term><replaceable class="parameter">function_name</replaceable></term>
124    <term><replaceable class="parameter">operator_name</replaceable></term>
125    <term><replaceable class="parameter">policy_name</replaceable></term>
126    <term><replaceable class="parameter">procedure_name</replaceable></term>
127    <term><replaceable class="parameter">routine_name</replaceable></term>
128    <term><replaceable class="parameter">rule_name</replaceable></term>
129    <term><replaceable class="parameter">trigger_name</replaceable></term>
130    <listitem>
131     <para>
132      The name of the object to be commented.  Names of tables,
133      aggregates, collations, conversions, domains, foreign tables, functions,
134      indexes, operators, operator classes, operator families, procedures, routines, sequences,
135      statistics, text search objects, types, and views can be
136      schema-qualified. When commenting on a column,
137      <replaceable class="parameter">relation_name</replaceable> must refer
138      to a table, view, composite type, or foreign table.
139     </para>
140    </listitem>
141   </varlistentry>
142
143   <varlistentry>
144    <term><replaceable class="parameter">table_name</replaceable></term>
145    <term><replaceable class="parameter">domain_name</replaceable></term>
146    <listitem>
147     <para>
148      When creating a comment on a constraint, a trigger, a rule or
149      a policy these parameters specify the name of the table or domain on
150      which that object is defined.
151     </para>
152    </listitem>
153   </varlistentry>
154
155   <varlistentry>
156     <term><replaceable>source_type</replaceable></term>
157     <listitem>
158      <para>
159       The name of the source data type of the cast.
160      </para>
161     </listitem>
162    </varlistentry>
163
164    <varlistentry>
165     <term><replaceable>target_type</replaceable></term>
166     <listitem>
167      <para>
168       The name of the target data type of the cast.
169      </para>
170     </listitem>
171    </varlistentry>
172
173   <varlistentry>
174    <term><replaceable class="parameter">argmode</replaceable></term>
175    <listitem>
176     <para>
177      The mode of a function, procedure, or aggregate
178      argument: <literal>IN</literal>, <literal>OUT</literal>,
179      <literal>INOUT</literal>, or <literal>VARIADIC</literal>.
180      If omitted, the default is <literal>IN</literal>.
181      Note that <command>COMMENT</command> does not actually pay
182      any attention to <literal>OUT</literal> arguments, since only the input
183      arguments are needed to determine the function's identity.
184      So it is sufficient to list the <literal>IN</literal>, <literal>INOUT</literal>,
185      and <literal>VARIADIC</literal> arguments.
186     </para>
187    </listitem>
188   </varlistentry>
189
190   <varlistentry>
191    <term><replaceable class="parameter">argname</replaceable></term>
192    <listitem>
193     <para>
194      The name of a function, procedure, or aggregate argument.
195      Note that <command>COMMENT</command> does not actually pay
196      any attention to argument names, since only the argument data
197      types are needed to determine the function's identity.
198     </para>
199    </listitem>
200   </varlistentry>
201
202   <varlistentry>
203    <term><replaceable class="parameter">argtype</replaceable></term>
204    <listitem>
205     <para>
206      The data type of a function, procedure, or aggregate argument.
207     </para>
208    </listitem>
209   </varlistentry>
210
211   <varlistentry>
212    <term><replaceable class="parameter">large_object_oid</replaceable></term>
213    <listitem>
214     <para>
215      The OID of the large object.
216     </para>
217    </listitem>
218   </varlistentry>
219
220   <varlistentry>
221    <term><replaceable class="parameter">left_type</replaceable></term>
222    <term><replaceable class="parameter">right_type</replaceable></term>
223    <listitem>
224     <para>
225      The data type(s) of the operator's arguments (optionally
226      schema-qualified).  Write <literal>NONE</literal> for the missing argument
227      of a prefix or postfix operator.
228     </para>
229    </listitem>
230   </varlistentry>
231
232    <varlistentry>
233     <term><literal>PROCEDURAL</literal></term>
234     <listitem>
235      <para>
236       This is a noise word.
237      </para>
238     </listitem>
239    </varlistentry>
240
241    <varlistentry>
242     <term><replaceable>type_name</replaceable></term>
243
244     <listitem>
245      <para>
246       The name of the data type of the transform.
247      </para>
248     </listitem>
249    </varlistentry>
250
251    <varlistentry>
252     <term><replaceable>lang_name</replaceable></term>
253
254     <listitem>
255      <para>
256       The name of the language of the transform.
257      </para>
258     </listitem>
259    </varlistentry>
260
261   <varlistentry>
262    <term><replaceable class="parameter">text</replaceable></term>
263    <listitem>
264     <para>
265      The new comment, written as a string literal; or <literal>NULL</literal>
266      to drop the comment.
267     </para>
268    </listitem>
269   </varlistentry>
270
271  </variablelist>
272 </refsect1>
273
274 <refsect1>
275  <title>Notes</title>
276
277  <para>
278   There is presently no security mechanism for viewing comments: any user
279   connected to a database can see all the comments for objects in
280   that database.  For shared objects such as
281   databases, roles, and tablespaces, comments are stored globally so any
282   user connected to any database in the cluster can see all the comments
283   for shared objects.  Therefore, don't put security-critical
284   information in comments.
285  </para>
286 </refsect1>
287
288 <refsect1>
289  <title>Examples</title>
290
291  <para>
292   Attach a comment to the table <literal>mytable</literal>:
293
294<programlisting>
295COMMENT ON TABLE mytable IS 'This is my table.';
296</programlisting>
297
298   Remove it again:
299
300<programlisting>
301COMMENT ON TABLE mytable IS NULL;
302</programlisting>
303  </para>
304
305  <para>
306   Some more examples:
307
308<programlisting>
309COMMENT ON ACCESS METHOD gin IS 'GIN index access method';
310COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance';
311COMMENT ON CAST (text AS int4) IS 'Allow casts from text to int4';
312COMMENT ON COLLATION "fr_CA" IS 'Canadian French';
313COMMENT ON COLUMN my_table.my_column IS 'Employee ID number';
314COMMENT ON CONVERSION my_conv IS 'Conversion to UTF8';
315COMMENT ON CONSTRAINT bar_col_cons ON bar IS 'Constrains column col';
316COMMENT ON CONSTRAINT dom_col_constr ON DOMAIN dom IS 'Constrains col of domain';
317COMMENT ON DATABASE my_database IS 'Development Database';
318COMMENT ON DOMAIN my_domain IS 'Email Address Domain';
319COMMENT ON EVENT TRIGGER abort_ddl IS 'Aborts all DDL commands';
320COMMENT ON EXTENSION hstore IS 'implements the hstore data type';
321COMMENT ON FOREIGN DATA WRAPPER mywrapper IS 'my foreign data wrapper';
322COMMENT ON FOREIGN TABLE my_foreign_table IS 'Employee Information in other database';
323COMMENT ON FUNCTION my_function (timestamp) IS 'Returns Roman Numeral';
324COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee ID';
325COMMENT ON LANGUAGE plpython IS 'Python support for stored procedures';
326COMMENT ON LARGE OBJECT 346344 IS 'Planning document';
327COMMENT ON MATERIALIZED VIEW my_matview IS 'Summary of order history';
328COMMENT ON OPERATOR ^ (text, text) IS 'Performs intersection of two texts';
329COMMENT ON OPERATOR - (NONE, integer) IS 'Unary minus';
330COMMENT ON OPERATOR CLASS int4ops USING btree IS '4 byte integer operators for btrees';
331COMMENT ON OPERATOR FAMILY integer_ops USING btree IS 'all integer operators for btrees';
332COMMENT ON POLICY my_policy ON mytable IS 'Filter rows by users';
333COMMENT ON PROCEDURE my_proc (integer, integer) IS 'Runs a report';
334COMMENT ON PUBLICATION alltables IS 'Publishes all operations on all tables';
335COMMENT ON ROLE my_role IS 'Administration group for finance tables';
336COMMENT ON ROUTINE my_routine (integer, integer) IS 'Runs a routine (which is a function or procedure)';
337COMMENT ON RULE my_rule ON my_table IS 'Logs updates of employee records';
338COMMENT ON SCHEMA my_schema IS 'Departmental data';
339COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys';
340COMMENT ON SERVER myserver IS 'my foreign server';
341COMMENT ON STATISTICS my_statistics IS 'Improves planner row estimations';
342COMMENT ON SUBSCRIPTION alltables IS 'Subscription for all operations on all tables';
343COMMENT ON TABLE my_schema.my_table IS 'Employee Information';
344COMMENT ON TABLESPACE my_tablespace IS 'Tablespace for indexes';
345COMMENT ON TEXT SEARCH CONFIGURATION my_config IS 'Special word filtering';
346COMMENT ON TEXT SEARCH DICTIONARY swedish IS 'Snowball stemmer for Swedish language';
347COMMENT ON TEXT SEARCH PARSER my_parser IS 'Splits text into words';
348COMMENT ON TEXT SEARCH TEMPLATE snowball IS 'Snowball stemmer';
349COMMENT ON TRANSFORM FOR hstore LANGUAGE plpythonu IS 'Transform between hstore and Python dict';
350COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for RI';
351COMMENT ON TYPE complex IS 'Complex number data type';
352COMMENT ON VIEW my_view IS 'View of departmental costs';
353</programlisting></para>
354 </refsect1>
355
356 <refsect1>
357  <title>Compatibility</title>
358
359  <para>
360   There is no <command>COMMENT</command> command in the SQL standard.
361  </para>
362 </refsect1>
363</refentry>
364