Defines or changes the comment of an object.

Synopsis

  1. COMMENT ON
  2. { TABLE <object_name> |
  3. COLUMN <relation_name.column_name> |
  4. AGGREGATE <agg_name> (<agg_signature>) |
  5. CAST (<source_type> AS <target_type>) |
  6. COLLATION <object_name>
  7. CONSTRAINT <constraint_name> ON <table_name> |
  8. CONVERSION <object_name> |
  9. DATABASE <object_name> |
  10. DOMAIN <object_name> |
  11. EXTENSION <object_name> |
  12. FOREIGN DATA WRAPPER <object_name> |
  13. FOREIGN TABLE <object_name> |
  14. FUNCTION <func_name> ([[<argmode>] [<argname>] <argtype> [, ...]]) |
  15. INDEX <object_name> |
  16. LARGE OBJECT <large_object_oid> |
  17. MATERIALIZED VIEW <object_name> |
  18. OPERATOR <operator_name> (<left_type>, <right_type>) |
  19. OPERATOR CLASS <object_name> USING <index_method> |
  20. [PROCEDURAL] LANGUAGE <object_name> |
  21. RESOURCE GROUP <object_name> |
  22. RESOURCE QUEUE <object_name> |
  23. ROLE <object_name> |
  24. RULE <rule_name> ON <table_name> |
  25. SCHEMA <object_name> |
  26. SEQUENCE <object_name> |
  27. SERVER <object_name> |
  28. TABLESPACE <object_name> |
  29. TEXT SEARCH CONFIGURATION <object_name> |
  30. TEXT SEARCH DICTIONARY <object_name> |
  31. TEXT SEARCH PARSER <object_name> |
  32. TEXT SEARCH TEMPLATE <object_name> |
  33. TRIGGER <trigger_name> ON <table_name> |
  34. TYPE <object_name> |
  35. VIEW <object_name> }
  36. IS '<text>'

where agg_signature is:

  1. * |
  2. [ <argmode> ] [ <argname> ] <argtype> [ , ... ] |
  3. [ [ <argmode> ] [ <argname> ] <argtype> [ , ... ] ] ORDER BY [ <argmode> ] [ <argname> ] <argtype> [ , ... ]

Description

COMMENT stores a comment about a database object. Only one comment string is stored for each object. To remove a comment, write NULL in place of the text string. Comments are automatically dropped when the object is dropped.

For most kinds of object, only the object’s owner can set the comment. Roles don’t have owners, so the rule for COMMENT ON ROLE is that you must be superuser to comment on a superuser role, or have the CREATEROLE privilege to comment on non-superuser roles. Of course, a superuser can comment on anything.

Comments can be easily retrieved with the psql meta-commands \dd, \d+, and \l+. Other user interfaces to retrieve comments can be built atop the same built-in functions that psql uses, namely obj_description, col_description, and shobj_description.

Parameters

object_name

relation_name.column_name

agg_name

constraint_name

func_name

operator_name

rule_name

trigger_name

The name of the object to be commented. Names of tables, aggregates, collations, conversions, domains, foreign tables, functions, indexes, operators, operator classes, operator families, sequences, text search objects, types, views, and materialized views can be schema-qualified. When commenting on a column, relation_name must refer to a table, view, materialized view, composite type, or foreign table.

Note

Greenplum Database does not support triggers.

source_type

The name of the source data type of the cast.

target_type

The name of the target data type of the cast.

argmode

The mode of a function or aggregate argument: either IN, OUT, INOUT, or VARIADIC. If omitted, the default is IN. Note that COMMENT does not actually pay any attention to OUT arguments, since only the input arguments are needed to determine the function’s identity. So it is sufficient to list the IN, INOUT, and VARIADIC arguments.

argname

The name of a function or aggregate argument. Note that COMMENT ON FUNCTION does not actually pay any attention to argument names, since only the argument data types are needed to determine the function’s identity.

argtype

The data type of a function or aggregate argument.

large_object_oid

The OID of the large object.

Note

Greenplum Database does not support the PostgreSQL large object facility for streaming user data that is stored in large-object structures.

left_type

right_type

The data type(s) of the operator’s arguments (optionally schema-qualified). Write NONE for the missing argument of a prefix or postfix operator.

PROCEDURAL

This is a noise word.

text

The new comment, written as a string literal; or NULL to drop the comment.

Notes

There is presently no security mechanism for viewing comments: any user connected to a database can see all the comments for objects in that database. For shared objects such as databases, roles, and tablespaces, comments are stored globally so any user connected to any database in the cluster can see all the comments for shared objects. Therefore, do not put security-critical information in comments.

Examples

Attach a comment to the table mytable:

  1. COMMENT ON TABLE mytable IS 'This is my table.';

Remove it again:

  1. COMMENT ON TABLE mytable IS NULL;

Some more examples:

  1. COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance';
  2. COMMENT ON CAST (text AS int4) IS 'Allow casts from text to int4';
  3. COMMENT ON COLLATION "fr_CA" IS 'Canadian French';
  4. COMMENT ON COLUMN my_table.my_column IS 'Employee ID number';
  5. COMMENT ON CONVERSION my_conv IS 'Conversion to UTF8';
  6. COMMENT ON CONSTRAINT bar_col_cons ON bar IS 'Constrains column col';
  7. COMMENT ON DATABASE my_database IS 'Development Database';
  8. COMMENT ON DOMAIN my_domain IS 'Email Address Domain';
  9. COMMENT ON EXTENSION hstore IS 'implements the hstore data type';
  10. COMMENT ON FOREIGN DATA WRAPPER mywrapper IS 'my foreign data wrapper';
  11. COMMENT ON FOREIGN TABLE my_foreign_table IS 'Employee Information in other database';
  12. COMMENT ON FUNCTION my_function (timestamp) IS 'Returns Roman Numeral';
  13. COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee ID';
  14. COMMENT ON LANGUAGE plpython IS 'Python support for stored procedures';
  15. COMMENT ON LARGE OBJECT 346344 IS 'Planning document';
  16. COMMENT ON OPERATOR ^ (text, text) IS 'Performs intersection of two texts';
  17. COMMENT ON OPERATOR - (NONE, integer) IS 'Unary minus';
  18. COMMENT ON OPERATOR CLASS int4ops USING btree IS '4 byte integer operators for btrees';
  19. COMMENT ON OPERATOR FAMILY integer_ops USING btree IS 'all integer operators for btrees';
  20. COMMENT ON ROLE my_role IS 'Administration group for finance tables';
  21. COMMENT ON RULE my_rule ON my_table IS 'Logs updates of employee records';
  22. COMMENT ON SCHEMA my_schema IS 'Departmental data';
  23. COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys';
  24. COMMENT ON SERVER myserver IS 'my foreign server';
  25. COMMENT ON TABLE my_schema.my_table IS 'Employee Information';
  26. COMMENT ON TABLESPACE my_tablespace IS 'Tablespace for indexes';
  27. COMMENT ON TEXT SEARCH CONFIGURATION my_config IS 'Special word filtering';
  28. COMMENT ON TEXT SEARCH DICTIONARY swedish IS 'Snowball stemmer for Swedish language';
  29. COMMENT ON TEXT SEARCH PARSER my_parser IS 'Splits text into words';
  30. COMMENT ON TEXT SEARCH TEMPLATE snowball IS 'Snowball stemmer';
  31. COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for RI';
  32. COMMENT ON TYPE complex IS 'Complex number data type';
  33. COMMENT ON VIEW my_view IS 'View of departmental costs';

Compatibility

There is no COMMENT statement in the SQL standard.

Parent topic: SQL Commands