Re: Reserve a value in a serial type field - Mailing list pgsql-general

From Shane Ambler
Subject Re: Reserve a value in a serial type field
Date
Msg-id 45ABE0F4.9060004@007Marketing.com
Whole thread Raw
In response to Reserve a value in a serial type field  ("Albert" <alberto.molteni@libero.it>)
Responses Re: Reserve a value in a serial type field
List pgsql-general
Albert wrote:
> Hi all. I have this issue: I need to load a value for an integer field
> (with auto increment) which I implemented with a serial type and to
> avoid inserts with that value in this field. The task is for a
> distributed program I'm creating and I wonder if there is an efficient
> solution for it.

Is this the initial loading of data or during normal usage?

> I thought about setting the current value of the sequence when loading
> the needed value..is it a solution? Is there something more efficient?

If you are loading the initial data to begin using the db then setting
sequence values will be fine.

If you are thinking about doing this constantly with normal usage then I
would say drop the serial type and just use a normal int column. A
unique index on the column will stop the duplicate value inserts and
allow your program to workout the values it wants to use.

If you are planning to keep changing the sequence next_value there is no
real point of using the serial and you will find you will get problems
with one client getting the current_value right before another program
increases the value and inserts the same value as the first client.


--

Shane Ambler
pgSQL@007Marketing.com

Get Sheeky @ http://Sheeky.Biz

pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: Avoiding empty queries in tsearch
Next
From: "Albert"
Date:
Subject: Re: Reserve a value in a serial type field