Re: Lazy constraints / defaults - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Lazy constraints / defaults
Date
Msg-id 10863.1205087115@sss.pgh.pa.us
Whole thread Raw
In response to Lazy constraints / defaults  ("Michał Zaborowski" <michal.zaborowski@gmail.com>)
Responses Re: Lazy constraints / defaults  ("Dawid Kuroczko" <qnex42@gmail.com>)
List pgsql-hackers
"Michał Zaborowski" <michal.zaborowski@gmail.com> writes:
>  I would like to be able to add CONSTRAINT and/or DEFAULT with out
> affecting old rows.

You mean without actually checking that the old rows satisfy the
constraint?  There's approximately zero chance that that proposal
will be accepted.

> Yes, it sounds strange, but... Let's say I have
> big table, I want to add new column, with DEFAULT and NOT NULL.
> Normally it means long exclusive lock. So - right now I'm adding plain
> new column, then DEFAULT, then UPDATE on all rows in chunks, then NOT
> NULL... Can it be little simpler?

Just do it all in one ALTER command.

alter table tab add column col integer not null default 42 check (col > 0);
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Dawid Kuroczko"
Date:
Subject: Re: Idea: Comments on system catalogs?
Next
From: Michael Meskes
Date:
Subject: Re: timestamp datatype cleanup