Re: Reserve a value in a serial type field

From: Shane Ambler <pgsql(at)007Marketing(dot)com>
To: Albert <alberto(dot)molteni(at)libero(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Reserve a value in a serial type field
Date: 2007-01-15 20:15:48
Message-ID: 45ABE0F4.9060004@007Marketing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)007Marketing(dot)com

Get Sheeky @ http://Sheeky.Biz

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Albert 2007-01-15 20:44:57 Re: Reserve a value in a serial type field
Previous Message Christian Maier 2007-01-15 19:11:04 postmaster disconnects after heavy load inserts from plperlu -> waht to do?