Re: Deferrable Unique Constraints - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Deferrable Unique Constraints
Date
Msg-id 87vf9jyl16.fsf@stark.xeocode.com
Whole thread Raw
In response to Re: Deferrable Unique Constraints  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Deferrable Unique Constraints  (Neil Conway <neilc@samurai.com>)
List pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Greg Stark <gsstark@mit.edu> writes:
> > Off the top of my head it seems the way to go about doing this would be to
> > simply not insert the records in the index until commit time. This doesn't
> > actually sound so hard, is there any problem with this approach?
> 
> Yeah:
>     begin;
>     insert into foo (key, ...) values (33, ...);
>     select * from foo where key = 33;
>     ...
> 
> If the SELECT uses an indexscan it will fail to find the just-inserted
> row.

Well presumably you would need a non-unique index created for query execution
purposes. The unique index would be purely for enforcing the constraint.

-- 
greg



pgsql-hackers by date:

Previous
From: "Serguei A. Mokhov"
Date:
Subject: Re: Patent issues and 8.1
Next
From: Tom Lane
Date:
Subject: Re: bug w/ cursors and savepoints