How do you add a column to an existing table?
Instruction: In PostgreSQL, a disposable practice_customers table already has rows and no nickname column. Add an optional text nickname, explain the value in existing rows, and describe what must be resolved before making it NOT NULL.
Updated
Official answer
For the supplied PostgreSQL table, add the nullable text column with:
ALTER TABLE practice_customers ADD COLUMN nickname text;
Existing rows have NULL in nickname because no default is specified. A later INSERT that omits it also receives NULL unless a default is subsequently defined.
If the requirement is eventually NOT NULL, first define a valid value for every existing row and ensure concurrent writes will satisfy the rule. Adding an arbitrary placeholder just to pass a constraint can corrupt the business meaning. Validate the data and apply the constraint through an appropriate migration.
Operational cost depends on the engine/version, default expression, constraints and table size. Modern PostgreSQL can add a constant default without rewriting every row immediately, but the operation still has locking requirements. Test representative migrations and account for lock waits and application compatibility instead of promising no disruption.
Assessment: Correct syntax, existing-row behavior, and a plan for nullability and concurrent writers.