• Data Warehouse Service

  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. SQL Reference
  5. SQL Syntax



Only one comment string is stored for each object. To modify a comment, issue a new COMMENT command for the same object. To remove a comment, write NULL in place of the text string. Comments are automatically dropped when their object is dropped.


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.

For most kinds of objects, only the owner of objects can set the comment. Roles do not have owners, so the rule for COMMENT ON ROLE is that you must be administrator to comment on an administrator role, or have the CREATEROLE permission to comment on non-administrator roles. An administrator can comment on anything.


  AGGREGATE agg_name (agg_type [, ...] ) |
  CAST (source_type AS target_type) |
  COLLATION object_name |
  COLUMN { table_name.column_name | view_name.column_name } |
  CONSTRAINT constraint_name ON table_name |
  CONVERSION object_name |
  DATABASE object_name |
  DOMAIN object_name |
  EXTENSION object_name |
  FOREIGN DATA WRAPPER object_name |
  FOREIGN TABLE object_name |
  FUNCTION function_name ( [ {[ argmode ] [ argname ] argtype} [, ...] ] ) |
  INDEX object_name |
  LARGE OBJECT large_object_oid |
  OPERATOR operator_name (left_type, right_type) |
  OPERATOR CLASS object_name USING index_method |
  OPERATOR FAMILY object_name USING index_method |
  [ PROCEDURAL ] LANGUAGE object_name |
  ROLE object_name |
  RULE rule_name ON table_name |
  SCHEMA object_name |
  SERVER object_name |
  TABLE object_name |
  TABLESPACE object_name |
  TEXT SEARCH PARSER object_name |
  TEXT SEARCH TEMPLATE object_name |
  TYPE object_name |
  VIEW object_name
   IS 'text';

Parameter Description

  • agg_name

    Specifies the new name of an aggregation function.

  • agg_type

    Specifies the data types of the aggregation function parameters.

  • source_type

    Specifies the name of the source data type of the cast.

  • target_type

    Specifies the name of the target data type of the cast.

  • object_name

    Specifies the name of the object to be commented.

  • table_name.column_name


    Specifies the column whose comment is defined or modified. You can add the table name or view name as the prefix.

  • constraint_name

    Specifies the table constraints whose comment is defined or modified.

  • table_name

    Specifies the table name.

  • function_name

    Specifies the function whose comment is defined or modified.

  • argmode,argname,argtype

    Specifies the schema, name, and type of the function parameters.

  • large_object_oid

    Specifies the OID of the large object whose comment is defined or modified.

  • operator_name

    Specifies the name of the operator.

  • 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.

  • text

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


CREATE TABLE tpcds.customer_demographics_t2
    CD_DEMO_SK                INTEGER               NOT NULL,
    CD_GENDER                 CHAR(1)                       ,
    CD_MARITAL_STATUS         CHAR(1)                       ,
    CD_EDUCATION_STATUS       CHAR(20)                      ,
    CD_PURCHASE_ESTIMATE      INTEGER                       ,
    CD_CREDIT_RATING          CHAR(10)                      ,
    CD_DEP_COUNT              INTEGER                       ,
    CD_DEP_EMPLOYED_COUNT     INTEGER                       ,


-- Add a comment to the tpcds.customer_demographics_t2.cd_demo_sk column:
COMMENT ON COLUMN tpcds.customer_demographics_t2.cd_demo_sk IS 'Primary key of customer demographics table.';

-- Create a view consisting of rows with c_customer_sk smaller than 150:
CREATE VIEW tpcds.customer_details_view_v2 AS
    SELECT *
    FROM tpcds.customer
    WHERE c_customer_sk < 150;

-- Add a comment to the tpcds.customer_details_view_v2 view:
COMMENT ON VIEW tpcds.customer_details_view_v2 IS 'View of customer detail';

-- Delete the view:
DROP VIEW tpcds.customer_details_view_v2;

-- Delete the tpcds.customer_demographics_t2 table:
DROP TABLE tpcds.customer_demographics_t2;