Use COMMENT ON to add, update, or remove descriptions on tables, columns, and foreign tables in Hologres. The syntax is compatible with PostgreSQL COMMENT.
Syntax
COMMENT ON
{
TABLE <table_name> |
COLUMN <table_name.column_name> |
FOREIGN TABLE <foreign_table_name>
}
IS '<text>';Parameters
| Parameter | Description |
|---|---|
TABLE <table_name> | The internal table to comment on. Use the format schema_name.table_name to specify a non-default schema. |
COLUMN <table_name.column_name> | The column to comment on, in the format table_name.column_name. |
FOREIGN TABLE <foreign_table_name> | The foreign table to comment on. |
'<text>' | The comment text. Enclose in single quotation marks. |
Add comments when creating a table
Wrap COMMENT ON statements in the same transaction as CREATE TABLE to add comments in a single operation.
BEGIN;
CREATE TABLE public."user" (
"id" text NOT NULL,
"name" text NOT NULL
);
COMMENT ON TABLE public."user" IS 'user property table';
COMMENT ON COLUMN public."user".id IS 'ID card number';
COMMENT ON COLUMN public."user".name IS 'name';
COMMIT;Add or update comments after table creation
Run COMMENT ON statements directly against any existing table, column, or foreign table.
-- Add a comment to an internal table.
COMMENT ON TABLE table_name IS 'my comments on table table_name.';
-- Add a comment to a column.
COMMENT ON COLUMN table_name.col1 IS 'This my first col1';
-- Add a comment to a foreign table.
COMMENT ON FOREIGN TABLE foreign_table IS 'comments on my foreign table';Query comments
To verify that comments were applied, query pg_catalog.pg_attribute. The following statement returns the column names, data types, nullable flags, and descriptions for a given table:
SELECT a.attname AS "Column",
pg_catalog.format_type(a.atttypid, a.atttypmod) AS "Type",
a.attnotnull AS "Nullable",
pg_catalog.col_description(a.attrelid, a.attnum) AS "Description"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0
AND NOT a.attisdropped
AND a.attrelid = '<schema.tablename>'::regclass::oid
ORDER BY a.attnum;Replace <schema.tablename> with the actual schema-qualified table name, for example public.user.
What's next
For other DDL statements supported by Hologres, see:
该文章对您有帮助吗?