Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

COMMENT ON

Defines, replaces, appends to, or removes the description of relations and columns.

COMMENT ON TABLE users IS 'User registry';
COMMENT ON DATABASE app IS 'Application database';
COMMENT ON COLUMN users.email IS 'Email address';
COMMENT ON COLUMN users.email IS APPEND ' used for authentication';
COMMENT ON COLUMN users.email IS NULL;
COMMENT ON VIEW active_users IS 'Active users';
COMMENT ON MATERIALIZED VIEW user_totals IS 'Totals by user';
COMMENT ON INDEX users_email_idx IS 'Lookup by email';
COMMENT ON SEQUENCE users_id_seq IS 'User identifiers';
COMMENT ON COLLECTION events IS 'Incoming events';
COMMENT ON QUEUE pending_jobs IS 'Pending jobs';
COMMENT ON MEMORY TABLE request_cache IS 'Session cache';
COMMENT ON SCHEMA app IS 'Application objects';
COMMENT ON DOMAIN app.email IS 'Validated address';
COMMENT ON TYPE app.status IS 'Processing state';
COMMENT ON FUNCTION app.normalize_email(text) IS 'Normalizes addresses';
COMMENT ON ROLE analyst IS 'Analytics team';
COMMENT ON EXTENSION amphi_openai IS 'AI provider';
COMMENT ON FOREIGN TABLE app.remote_users IS 'Remote registry';
COMMENT ON SERVER csv_server IS 'CSV source';
COMMENT ON EXTERNAL_CONNECTION csv_connection IS 'Source credentials';
COMMENT ON CONSTRAINT users_email_key ON app.users IS 'Unique email';
COMMENT ON TRIGGER users_audit ON app.users IS 'Records changes';

For several columns of one table, Amphi provides an extension:

COMMENT ON TABLE users
  COLUMN name IS 'Full name'
  COLUMN email IS APPEND ' used for authentication'
  COLUMN bio IS NULL;

IS replaces the text, IS APPEND concatenates text to the existing comment, and IS NULL removes it. Column comments are supported on tables, views, materialized views, collections, queues, and memory tables. The COMMENT ON COLUMN table.column form remains available for PostgreSQL compatibility. Comments are metadata, not lexical -- or /* ... */ comments.

Relation comments are also accepted on heap tables and their partitions, memory tables, collections, queues, views, and materialized views; indexes, sequences, and foreign tables accept an object comment. Foreign tables also accept column comments. Memory tables are volatile: their comments disappear when the table is discarded on restart and are not included in dumps.

Other supported targets are SCHEMA, DOMAIN, TYPE, FUNCTION, AGGREGATE, ROLE, GROUP, TABLESPACE, PARTITION_POLICY, ACCESS_POLICY, CONSTRAINT, TRIGGER, EXTENSION, FOREIGN TABLE, SERVER, EXTERNAL_CONNECTION, SECRET, OPCLASS, OPERATOR, and CAST. Operators must include both operand types (use NONE for a missing side of a unary operator); casts use (source AS target). Overloaded routines must include their argument type list; constraints and triggers use ... ON table. Their comments are exposed through sys.catalog_object_comments and included in logical dumps when that object type is already exported. For casts, object_name in that view is the target type and owner_name is the source type.

Foreign data wrappers do not support comments yet. SCHEDULE comments appear in sys.catalog_object_comments, but schedules and their comments are not included in the current logical dump. COMMENT ON SECRET is admin-only and autocommit-only. Its metadata is separate from the encrypted value and appears in sys.catalog_object_comments. Secrets and their comments are not exported by dumps. Built-in operator, opclass, and cast comments are restored after their catalog identities are available. Databases, foreign servers, and external connections support comments. Database comments are cluster-wide metadata and can be changed by the database owner or an admin, outside transactions. Single-database and --cluster dumps preserve them. Dumps restore only definitions without options. Connections with options, including SECRET references, are omitted because dumps do not contain the secret objects needed for restore. Comments for omitted definitions are omitted too. Internal objects (such as TOAST relations) are not public targets. The Console Comments tab is available on database, foreign server, relation, domain, and function detail panels; other SQL-supported types are managed through the SQL editor.