COMMENT
Description
Defines or changes the comment of an object.
Precautions
- Each object stores only one comment. Therefore, you need to modify a comment and issue a new COMMENT command to the same object. To delete the comment, write NULL at the position of the text string. When an object is deleted, the comment is automatically deleted.
- Currently, there is no security protection for viewing comments. Any user connected to a database can view all the comments for objects in the 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.
- To comment objects, you must be an object owner or user granted the COMMENT permission. System administrators have this permission by default.
- Roles do not have owners, so the rule for COMMENT ON ROLE is that you must be a system administrator to comment on a SYSADMIN role, or have the CREATEROLE permission to comment on non-SYSADMIN roles. A system administrator can comment on all objects.
Syntax
COMMENT ON { 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 ( [ {[ argname ] [ argmode ] 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 | SCHEMA object_name | SERVER object_name | TABLE object_name | TABLESPACE object_name | TEXT SEARCH CONFIGURATION object_name | TEXT SEARCH DICTIONARY object_name | TEXT SEARCH PARSER object_name | TEXT SEARCH TEMPLATE object_name | TYPE object_name | VIEW object_name | TRIGGER trigger_name ON table_name } IS 'text';
Parameters
- agg_name
Name of an aggregate function.
- agg_type
Data type of the aggregate function parameters.
- source_type
Source data type in the type conversion.
- target_type
Target data type in the type conversion.
- object_name
Object name.
- table_name.column_name
view_name.column_name
Column name You can add the table name or view name as the prefix.
- constraint_name
Table constraint whose comment is defined or modified.
- table_name
Table name.
- function_name
Function name.
- argname,argmode,argtype
Name, schema, and type of the function parameters.
- large_object_oid
OID of a large object.
- operator_name
Operator name.
- left_type,right_type
Data type of the operator parameters (optionally schema-qualified). If the prefix or suffix operator does not exist, the NONE option can be added.
- trigger_name
Trigger name.
- text
Comments.
Examples
-- Create a schema. openGauss=# CREATE SCHEMA tpcds; -- Create the tpcds.customer table. openGauss=# CREATE TABLE tpcds.customer ( c_customer_sk INTEGER NOT NULL, c_customer_id CHAR(16) NOT NULL ); -- Insert multiple records into the table. openGauss=# INSERT INTO tpcds.customer VALUES (50, 'AAAAAAAABAAAAAAA'),(100, 'AAAAAAAACAAAAAAA'),(150, 'AAAAAAAADAAAAAAA'); -- Create the tpcds.customer_demographics_t2 table. openGauss=# 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 , CD_DEP_COLLEGE_COUNT INTEGER ) ; -- Comment out the tpcds.customer_demographics_t2.cd_demo_sk column. openGauss=# 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 less than 150. openGauss=# CREATE VIEW tpcds.customer_details_view_v2 AS SELECT * FROM tpcds.customer WHERE c_customer_sk < 150; -- Comment out the tpcds.customer_details_view_v2 view. openGauss=# COMMENT ON VIEW tpcds.customer_details_view_v2 IS 'View of customer detail'; -- Drop the view. openGauss=# DROP VIEW tpcds.customer_details_view_v2; -- Drop the tpcds.customer_demographics_t2 table. openGauss=# DROP TABLE tpcds.customer_demographics_t2; -- Drop the tpcds.customer table. openGauss=# DROP TABLE tpcds.customer; -- Drop the schema. openGauss=# DROP SCHEMA tpcds CASCADE;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot