The query ran fast and failed at the edge: no such column. You know the reason. The schema changed. The data didn’t. The fix is simple—add a new column. But done poorly, it breaks more than it fixes.
Adding a new column to a production database demands clarity. You must define its name, type, constraints, and default behavior before it touches live traffic. Will it allow NULLs? Should it have an index? Will it be backfilled, and if so, how will that load affect the system in peak hours?
In modern SQL, the syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
This works in PostgreSQL, MySQL, and most relational databases with small variations. But database platforms are not the same. In MySQL, adding a column with a default can lock the table. In PostgreSQL, large tables can take milliseconds, but only if the change is metadata-only. Adding NOT NULL to an existing column that has no default will rewrite all rows and can stall your system.