Skip to content

COMMENT ON

Comment on a database object.

COMMENT ON object name IS 'comment'
COMMENT ON CONSTRAINT name ON table IS 'comment'
object

One of the following: COLUMN, DATABASE, ROLE, SCHEMA, SEQUENCE, TABLE, VIEW, KEY, PROCEDURE.

name

Database object name. Use table.name for column names, such as match.ftscore.

If a stored procedure has arguments, you must identify them in the procedure name. For example, either of the following names would work for a procedure addteam with one VARCHAR(30) argument:

addteam(varchar(30))
addteam(name varchar(30))

If a stored procedure does not have any arguments, specify its name with parentheses. For example:

droptable()
CONSTRAINT name ON table

For constraints, specify the table name as well as the constraint name.

'comment'

The text string that you want to save for the named object. Use null to remove an existing comment. Use a new COMMENT ON command to modify a comment. You can see the current comment for an object by using the appropriate backslash command with the plus sign, such as \d+ or \l+.

Do not put sensitive information in comments; any user can see comments on shared objects such as databases and roles. In general, only object owners and superusers can comment on objects. You must be a superuser to comment on a superuser role. You must have CREATEROLE privilege to comment on non-superuser roles.

Examples

Comment on a table and a view:

premdb=# comment on table awayteam is 'Just a reference for atid in the match table';
COMMENT
premdb=# comment on view matchview is 'View of match table';
COMMENT
premdb=# \d+
                                 List of relations
 Schema |   Name    | Type  |  Owner  |                 Description                  
--------+-----------+-------+---------+----------------------------------------------
 public | awayteam  | table | brumsby | Just a reference for atid in the match table
 public | hometeam  | table | brumsby | 
 public | match     | table | brumsby | 
 public | matchview | view  | brumsby | View of match table
 public | season    | table | brumsby | 
 public | team      | table | brumsby | 
(6 rows)

Comment on a table column:

premdb=# comment on column match.ftscore is 'Full-time score';
COMMENT
premdb=# \d+ match
                        Table "public.match"
  Column  |            Type             | Modifiers |   Description   
----------+-----------------------------+-----------+-----------------
 seasonid | smallint                    |           | 
 matchday | timestamp without time zone |           | 
 htid     | smallint                    |           | 
 atid     | smallint                    |           | 
 ftscore  | character(3)                |           | Full-time score
 htscore  | character(3)                |           | 

Distribution: Hash (seasonid)

Comment on a stored procedure:

premdb=# comment on procedure addteam(varchar(30)) is 'Stored proc with varchar arg';
COMMENT

Comment on a primary key constraint for a table:

premdb=# comment on constraint match_pkey on match is 'Primary key constraint on seasonid';
COMMENT

Parent topic:SQL Commands