Re: Happy column adding (was RE: [HACKERS] Happy column dropping)

Hannu Krosing <hannu@tm.ee>

From: Hannu Krosing <hannu@tm.ee>
To: Hiroshi Inoue <Inoue@tpf.co.jp>
Cc: Don Baccus <dhogaza@pacifier.com>, PostgreSQL Development <pgsql-hackers@postgreSQL.org>, Peter Eisentraut <peter_e@gmx.net>
Date: 2000-01-26T08:45:42Z
Lists: pgsql-hackers
Hiroshi Inoue wrote:
> 
> > However, heap_getattr still won't see the default since it simply
> > checks to see of the attribute number falls off the end of the
> > tuple and then returns null.
> >
> 
> Sorry,the following question might be already answered but too
> many postings for me.
> 
> Do we have to refer default value for already inserted rows ?
> Doesn't 'default' have its meaning only when rows are about to be
> inserted ?

I think the case was about adding a NOT NULL column and setting current NULL 
columns to DEFAULT seemed like a natural thing to do.

But, considering the fact that DEFAULT can be something reaaly complex, like
function that does a lot of things, it may be better to have the constraints
checked at the end of transaction, like

BEGIN;
ALTER TABLE T1 ADD COLUMN C1 TEXT NOT NULL;
UPDATE T1 SET C1='MYDEFAULTVALUE';
COMMIT;

only IIRC we have quite poor support for DDL statements inside transactions.

---------------
Hannu