Thread: unique index

unique index

From
"Gus List"
Date:
Greetings,
 
 I have a very strange problem that I realy dont now if it should work this way or if it is a bug or a enviroment problem.
 
I'm running postgres 8.1.0 on a 'White Box Enterprise release 4' Linux box.
 
I've created a unique constraint for multiple fields (3) with a condition. Those fields are: bigint, varchar and varchar and the condition is status = 1 (status is a integer field) .
The condition works fine. It only lets me insert onde possible combination and if the status condition complies.
 
The problem is that when I try to insert an duplicate entry for testing I receive te error (ERROR:  duplicate key violates unique constraint "new_idx_UNIQ") but ALL RECORDS are DELETED. I don't think that this should happen.
 
Can any one give me some help on that ?
 
Regards,
Gus
 

Re: unique index

From
Michael Fuhr
Date:
On Mon, Feb 27, 2006 at 06:11:07PM -0300, Gus List wrote:
> The problem is that when I try to insert an duplicate entry for testing I
> receive te error (ERROR:  duplicate key violates unique constraint
> "new_idx_UNIQ") but ALL RECORDS are DELETED. I don't think that this should
> happen.

Are you in a transaction?  If so then the error is causing the
transaction to fail, which causes all of the transaction's work to
be rolled back (discarded).  That's how transactions work: either
everything succeeds or nothing does.  However, it's possible to
continue a transaction after an error if you use savepoints.

http://www.postgresql.org/docs/8.1/interactive/tutorial-transactions.html
http://www.postgresql.org/docs/8.1/interactive/sql-savepoint.html

--
Michael Fuhr