Re: Lazy constraints / defaults

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michał Zaborowski <michal(dot)zaborowski(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Lazy constraints / defaults
Date: 2008-03-09 18:25:15
Message-ID: 10863.1205087115@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"=?ISO-8859-2?Q?Micha=B3_Zaborowski?=" <michal(dot)zaborowski(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Meskes 2008-03-09 18:27:54 Re: timestamp datatype cleanup
Previous Message Dawid Kuroczko 2008-03-09 17:55:44 Re: Idea: Comments on system catalogs?