What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

You can document a PostgreSQL column with COMMENT ON COLUMN. In MySQL 8.4, a column comment is part of the column definition, so changing one on an existing table uses ALTER TABLE column-change syntax. Neither SQL feature requires a migration file by itself, though your team may require comments to go through its normal schema-deployment process.

How the two databases handle column comments

Database Set or change a comment Inspect comments Key consideration
PostgreSQL 17 COMMENT ON COLUMN psql d commands, col_description, or pg_description A new comment replaces the existing one. Comments are visible to database users.
MySQL 8.4 Put COMMENT in the column definition; change an existing column with ALTER TABLE. SHOW FULL COLUMNS, SHOW CREATE TABLE, or INFORMATION_SCHEMA.COLUMNS.COLUMN_COMMENT The documented comment limit is 1024 characters. Preserve the column’s full definition when altering it.

The examples below follow the PostgreSQL 17 and MySQL 8.4 manuals. Check the manual for your deployed version before applying syntax or assuming an operation’s impact.

Add or change a column comment in PostgreSQL

PostgreSQL provides a dedicated statement that targets the comment metadata without requiring you to restate the column’s type or other attributes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
COMMENT ON COLUMN public.customer.email IS 'Primary contact email supplied by the customer';

Use the schema-qualified name when needed to identify the intended object. The statement can target a column belonging to a table, view, composite type, or foreign table. A new comment replaces the existing comment for that object; to remove it, set the comment to NULL or an empty string:

COMMENT ON COLUMN public.customer.email IS NULL;

The PostgreSQL 17 reference says this command acquires a SHARE UPDATE EXCLUSIVE lock on the object. The comment is removed when the object itself is dropped. See the PostgreSQL 17 COMMENT reference for syntax and behavior.

View a PostgreSQL column comment

In psql, the d family of commands can display relation details, including comments. For SQL inspection, col_description returns a column’s description; the pg_description catalog stores optional object descriptions, with the column number recorded in objsubid for a column comment. The PostgreSQL 17 pg_description catalog reference explains the catalog fields.

Add or change a column comment in MySQL 8.4

In MySQL, the comment is a column-definition attribute. For a new table, include it in the column definition:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
CREATE TABLE customer (
  email VARCHAR(320) COMMENT 'Primary contact email supplied by the customer'
);

The MySQL 8.4 manual documents a maximum column-comment length of 1024 characters. The comment appears in SHOW CREATE TABLE, SHOW FULL COLUMNS, and INFORMATION_SCHEMA.COLUMNS.COLUMN_COMMENT. See the MySQL 8.4 CREATE TABLE reference.

Change an existing MySQL column comment

For an existing column, include the comment in an ALTER TABLE column-change operation. This illustrative statement is safe only if the existing definition really is a nullable-or-not-as-specified VARCHAR(320) with no other attributes that need preserving; use the actual definition from your table instead:

ALTER TABLE customer
  MODIFY COLUMN email VARCHAR(320)
    COMMENT 'Primary contact email supplied by the customer';

MODIFY COLUMN and CHANGE COLUMN operate on column definitions. Before executing an alteration, preserve the existing data type, nullability, default, generated expression, visibility, and any other relevant attributes. A shortened example that omits an attribute can unintentionally alter the column. MySQL’s ALTER TABLE reference describes the column-change forms and verification options.

Do not assume this operation is always instant or avoids a table rebuild: its operational impact can vary with server version, storage engine, and table configuration. The MySQL 8.4 reference does not establish a universal no-rebuild guarantee for a comment change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Query column comments in MySQL

To retrieve comments through SQL, filter the Information Schema by both schema and table so similarly named tables in different databases are not mixed together:

SELECT COLUMN_NAME, COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'app'
  AND TABLE_NAME = 'customer';

The COLUMNS table also reports data type, nullability, default, and other column attributes. For interactive inspection, use SHOW FULL COLUMNS or SHOW CREATE TABLE. Details are in the MySQL 8.4 Information Schema COLUMNS reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What “without a migration” means in practice

At the SQL level, PostgreSQL’s standalone comment statement changes the description directly. MySQL expresses the description as part of a column definition, so editing an existing column goes through ALTER TABLE. Whether either statement must be recorded in a migration file is a deployment-policy decision: a team can treat metadata-only DDL as a migration even when the database syntax does not require one.

PostgreSQL also warns that comments are not private: any user connected to the database can view comments for objects in that database. Do not put passwords, security-sensitive details, or other information that should remain confidential in a column description. The warning appears in the PostgreSQL 17 COMMENT reference.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.