Re: unique constraint - Mailing list pgsql-general

From Jeff Davis
Subject Re: unique constraint
Date
Msg-id 1287607397.28384.98.camel@jdavis-ux.asterdata.local
Whole thread Raw
In response to Re: unique constraint  (Michael Glaesemann <grzm@seespotcode.net>)
List pgsql-general
On Wed, 2010-10-20 at 16:10 -0400, Michael Glaesemann wrote:
> Upgrade if you can. Otherwise you can do two updates when rearranging paragraphs. The first updates them to an
"invalid"range which isn't used in "correct" data and so won't conflict with other values, and the second moves them
backto the valid range of positions. 
> Negative numbers are often used for this middle range.

The reason for the upgrade suggestion I believe was DEFERRABLE unique
constraints. These allow you to temporarily violate a unique constraint,
as long as it's correct at the end.

See:

  http://www.postgresql.org/docs/9.0/static/sql-createtable.html

and look for "DEFERRABLE".

You can also consider a constraint trigger:

  http://www.postgresql.org/docs/9.0/static/sql-createconstraint.html

Be careful to lock appropriately, however.

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: unique constraint
Next
From: John R Pierce
Date:
Subject: Re: postgre on virtual machine