<title>Description</title>
<para>
- <command>COMMENT</command> stores a comment about a database object.
+ <command>COMMENT</command> stores, replaces, or removes the comment on a
+ database object.
</para>
<para>
- Only one comment string is stored for each object, so to modify a comment,
- issue a new <command>COMMENT</command> command for the same object. To remove a
- comment, write <literal>NULL</literal> in place of the text string.
- Comments are automatically dropped when their object is dropped.
+ Only one comment string is stored for each object. Issuing a new
+ <command>COMMENT</command> command for the same object replaces the
+ existing comment. Specifying <literal>NULL</literal> or an empty
+ string (<literal>''</literal>) removes the comment. Comments are
+ automatically dropped when their object is dropped.
</para>
<para>
<term><replaceable class="parameter">string_literal</replaceable></term>
<listitem>
<para>
- The new comment contents, written as a string literal.
+ The new comment contents, written as a string literal. An empty string
+ (<literal>''</literal>) removes the comment.
</para>
</listitem>
</varlistentry>
<term><literal>NULL</literal></term>
<listitem>
<para>
- Write <literal>NULL</literal> to drop the comment.
+ Write <literal>NULL</literal> to remove the comment.
</para>
</listitem>
</varlistentry>
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';
+COMMENT ON VIEW my_view IS NULL;
</programlisting></para>
</refsect1>
ERROR: relation "six_wrong" does not exist
COMMENT ON INDEX six IS 'good index';
COMMENT ON INDEX six IS NULL;
+SELECT obj_description('six'::regclass, 'pg_class') IS NULL AS six_comment_is_null;
+ six_comment_is_null
+---------------------
+ t
+(1 row)
+
+COMMENT ON INDEX six IS 'add the comment back';
+COMMENT ON INDEX six IS ''; -- empty string removes the comment, same as NULL
+SELECT obj_description('six'::regclass, 'pg_class') IS NULL AS six_comment_is_null;
+ six_comment_is_null
+---------------------
+ t
+(1 row)
+
--
-- BTREE ascending/descending cases
--
COMMENT ON INDEX six_wrong IS 'bad index';
COMMENT ON INDEX six IS 'good index';
COMMENT ON INDEX six IS NULL;
+SELECT obj_description('six'::regclass, 'pg_class') IS NULL AS six_comment_is_null;
+COMMENT ON INDEX six IS 'add the comment back';
+COMMENT ON INDEX six IS ''; -- empty string removes the comment, same as NULL
+SELECT obj_description('six'::regclass, 'pg_class') IS NULL AS six_comment_is_null;
--
-- BTREE ascending/descending cases