Database changes look small in code but land like earthquakes in production. Adding a new column in SQL—whether to PostgreSQL, MySQL, or any relational system—requires precision. You must choose the column name, data type, default value, constraints, and whether it allows NULL. A single decision can break queries, fail API responses, or corrupt downstream data.
The syntax is simple:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
This works. But correctness depends on context. On large tables, adding a column locks writes and can block traffic. In cloud-managed databases, storage and I/O limits decide how long the operation runs. You must decide if the default is computed, static, or NULL, and whether to backfill data after the column exists.
Some teams use ALTER TABLE ... ADD COLUMN IF NOT EXISTS to make schema migrations idempotent. Others wrap changes in transactional migrations to avoid half-finished states. Always test with production-like data and measure execution time before shipping changes.