Martijn van Oosterhout <kleptog@svana.org> writes:
> However, from a semantic point of view, it would be a bit strange. If
> you added a column, updated some rows then set a default, that default
> might end up applying to every row, except the ones you already
> modified. With careful coding you may be able to get around this.
I suppose the update would have to check for these new columns and fill in the
default value when first updated.
But what do you do if the DEFAULT expression isn't immutable. Volatile DEFAULT
expressions are extremely common in databases... namely sequences.
It's too bad though. An efficient way to add a new column with a default would
clear up one of the missing feature of Postgres. Virtually every time I add a
new column I have to do this ALTER TABLE, ALTER COLUMN SET DEFAULT, UPDATE
TABLE, VACUUM FULL, ALTER COLUMN SET NOT NULL dance. It would be real nice if
you could add a new NOT NULL column with a default with a single command and
just move on.
--
greg