Skip to main content

COMMENT

Sets or changes the comment of an object.


Syntax

COMMENT ON
{ TABLE <object_name> |
COLUMN <relation_name.column_name> |
DATABASE <object_name> |
FUNCTION <func_name> ([[<arg_mode>] [<arg_name>] <arg_type> [, ...]]) |
MATERIALIZED VIEW <object_name> |
[PROCEDURAL] LANGUAGE <object_name> |
ROLE <object_name> |
SCHEMA <object_name> |
SEQUENCE <object_name> |
VIEW <object_name> }
IS 'text'

Description

You can use COMMENT to comments on database objects that you own.

Only one comment string is stored for each object. To remove a comment, use IS NULL. Once an object is dropped, its comment will be automatically dropped if any.

You can run psql meta-commands \dd, \d+, and \l+ to retrieve comments. You can create other user interfaces to retrieve comments by using the same built-in system functions that psql uses, such as obj_description, col_description, and shobj_description.

Do not put critical information in comments, because comments on objects in a database are visible to any user that is connected to the database.


Parameters

  • <object_name>, <relation_name.column_name>, or <func_name>

    The name of the database object on which you want to comment. You can specify the name with the schema qualification, if the database object is a table, function, materialized view, or view.

  • <arg_mode>

    The mode of the argument. Supported values include IN, OUT, INOUT, and VARIADIC. If this parameter is not specified, the default value IN is used. You do not need to list OUT arguments because COMMENT uses only input arguments to identify the function.

  • <arg_name>

    The name of the argument.

    Note that COMMENT ON FUNCTION uses only the data types of arguments to identify a function, instead of the argument names.

  • <arg_type>

    The data type of the argument.

  • PROCEDURAL

    A noise word.

  • <text>

    The comment string. To drop a comment, use NULL.


Examples

Comment on table sales:

COMMENT ON TABLE sales IS 'Sales information';

Drop the comment on table sales:

COMMENT ON TABLE sales IS NULL;

SQL standard compatibility

The SQL standard does not support COMMENT.