Re: Abort state on duplicated PKey in transactions

From: "Matthew T(dot) O'Connor" <matthew(at)zeut(dot)net>
To: "Haroldo Stenger" <hstenger(at)adinet(dot)com(dot)uy>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Abort state on duplicated PKey in transactions
Date: 2001-09-08 16:21:58
Message-ID: 002201c13882$63f83780$0b01010a@zeut
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> A solution, could be to query for the existance of the PK, just before the
> insertion. But there is a little span between the test and the
> insertion, where another insertion from another transaction could void
> the existance test. Any clever ideas on how to solve this? Using
> triggers maybe? Other solutions?
>

All you need to do is use a sequence. If you set the sequence to be the
primary key with a default value of nextval(seq_name) then you will never
have a collision. Alternatly if you need to know that number before you
start inserting you can select next_val(seq_name) before you inser and use
that. By the way the datatype serial automates exactly what I described.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Haroldo Stenger 2001-09-08 17:20:28 Abort state on duplicated PKey in transactions
Previous Message Larry Rosenman 2001-09-08 15:13:49 Re: [PATCHES] CURRENT CVS: MULTIBYTE: CANT CONNECT....