deferring pk constraint

From: "J(dot)V(dot)" <jvsrvcs(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: deferring pk constraint
Date: 2011-11-16 01:56:37
Message-ID: 4EC31855.9030007@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table with existing data for which I need to:

1) drop the single primary key column (int4)
2) recreate the column with the pk (not null) constraint deferred
3) repopulate the column from a sequence
4) enable the constraint

When I issue this command to add the column:

alter table <table_name> add column id INT4 NOT NULL;

I get an error saying:

ERROR: column "id" contains null values.

Is there a way to issue the "alter table..." command and defer the
constraint (did not see in online docs)
and then at some point enable it?

What would be the best approach here?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2011-11-16 01:57:25 Re: how to drop function?
Previous Message David Johnston 2011-11-16 01:49:52 Re: how to drop function?