Defines or modifies the comment of an object.

Syntax

COMMENT ON
{
  TABLE table_name |
  COLUMN table_name.column_name
} IS 'text'

Description

You can use the COMMENT command to store comments about database objects. To modify a comment of an object, you need to issue a new COMMENT command for the object. Only one comment string can be stored for each object. To delete a comment, specify an empty string (two consecutive single quotation marks with no space) for the text parameter. A comment is automatically deleted when the object is deleted.

Note Currently, no security mechanism is provided for comments. Any user who connects to the database can view all comments of the objects in the database. Do not include important security information in comments.

Parameters

Parameter Description
table_name The name of the table to be commented. The table name can be schema-qualified.
table_name.column_name The name of the column to be commented in the table. The table name can be schema-qualified.
text The new comment.

Examples

Attach a comment to a table named emp:

COMMENT ON TABLE emp IS 'Current employee information';

Attach a comment to the empno column of the emp table:

COMMENT ON COLUMN emp.empno IS 'Employee identification number';

Delete the comments:

COMMENT ON TABLE emp IS '';
COMMENT ON COLUMN emp.empno IS '';

View comments for emp table:

\dt+ emp;

View comments for columns in the emp table:

\d+ emp;