COMMENT - Amazon Redshift

COMMENT

Creates or changes a comment about a database object.

Syntax

COMMENT ON { TABLE object_name | COLUMN object_name.column_name | CONSTRAINT constraint_name ON table_name | DATABASE object_name | VIEW object_name } IS 'text' | NULL

Parameters

object_name

Name of the database object being commented on. You can add a comment to the following objects:

  • TABLE

  • COLUMN (also takes a column_name).

  • CONSTRAINT (also takes a constraint_name and table_name).

  • DATABASE

  • VIEW

IS 'text' | NULL

The comment text that you want to add or replace for the specified object. The text string is data type TEXT. Enclose the comment in single quotation marks. Set the value to NULL to remove the comment text.

column_name

Name of the column being commented on. Parameter of COLUMN. Follows a table specified in object_name.

constraint_name

Name of the constraint that is being commented on. Parameter of CONSTRAINT.

table_name

Name of a table containing the constraint. Parameter of CONSTRAINT.

Usage notes

You must be a superuser or the owner of a database object to add or update a comment.

Comments on databases may only be applied to the current database. A warning message is displayed if you attempt to comment on a different database. The same warning is displayed for comments on databases that don't exist.

Examples

The following example adds a comment to the SALES table.

COMMENT ON TABLE sales IS 'This table stores tickets sales data';

The following example displays the comment on the SALES table.

select obj_description('public.sales'::regclass); obj_description ------------------------------------- This table stores tickets sales data

The following example removes a comment from the SALES table.

COMMENT ON TABLE sales IS NULL;

The following example adds a comment to the EVENTID column of the SALES table.

COMMENT ON COLUMN sales.eventid IS 'Foreign-key reference to the EVENT table.';

The following example displays a comment on the EVENTID column (column number 5) of the SALES table.

select col_description( 'public.sales'::regclass, 5::integer ); col_description ----------------------------------------- Foreign-key reference to the EVENT table.

The following example adds a descriptive comment to the EVENT table.

comment on table event is 'Contains listings of individual events.';

To view comments, query the PG_DESCRIPTION system catalog. The following example returns the description for the EVENT table.

select * from pg_catalog.pg_description where objoid = (select oid from pg_class where relname = 'event' and relnamespace = (select oid from pg_catalog.pg_namespace where nspname = 'public') ); objoid | classoid | objsubid | description -------+----------+----------+---------------------------------------- 116658 | 1259 | 0 | Contains listings of individual events.

The following example uses the psql \dd command to view the comments. Amazon Redshift doesn't support psql directly. You must run psql commands from the PostgreSQL psql client.

Note

The \dd command returns comments only with the psql 8.x versions.

\dd event Object descriptions schema | name | object | description --------+-------+--------+----------------------------------------- public | event | table | Contains listings of individual events. (1 row)