Forum OpenACS Q&A: Response to impossible to add column not null in postgres?

Collapse
Posted by Don Baccus on
Currently when you add a column, Postgres just marks the new column as  being in existence without expanding the existing tuples in the table  to include it.  Whenever you update a row or insert a new one, the new column is materialized for the new rows.  When old rows are referenced, the non-materialized column is returned as a NULL.

This is very fast, but means that default values and "not null" and the like can't be implemented.  As you've noted, fixing this is on the  todo list, i.e. maintaining the fast existing method for simple "add column" commands, while doing the expensive form if default values or constraints inconsistent with the column being NULL are specified.  Getting rid of the fast, current method isn't a popular idea with thos e who have really huge, multi-GB tables (and PG traditionally has seen  a lot of use as a personal DB for storing huge amounts of astronomical and geographical data).