From: | Reece Hart <reece(at)harts(dot)net> |
---|---|
To: | "Decibel!" <decibel(at)decibel(dot)org> |
Cc: | Postgres List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Short-circuiting FK check for a newly-added field |
Date: | 2008-05-22 17:43:24 |
Message-ID: | 4835B0BC.2030404@harts.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, May 20, 2008 at 02:25:15PM -0400, Decibel! wrote:
> I need to add a field to a fairly large table. In the same alter statement
> I'd like to add a FK constraint on that new field. Is there any way to
> avoid the check of the table that the database is doing right now? The
> check is pointless because the newly added field is nothing but NULLs.
>
I don't see the problem. FK constraints don't fire on NULL values. I
think you might be imagining that a problem exists when it doesn't.
If the FK column is created as NOT NULL, there is a problem. The best
way to handle this case is to add the column (allowing nulls), populate
the columns, then alter the column to make it NOT NULL. You can wrap
that all in a transaction if you like.
> This is version 8.1.mumble.
>
You can get the version using select version().
-Reece
From | Date | Subject | |
---|---|---|---|
Next Message | Brijesh Shrivastav | 2008-05-22 18:49:38 | XML Support related questions |
Previous Message | Hiroaki Nakamura | 2008-05-22 17:11:57 | Is this correct usage of generate_series? |