Search Postgresql Archives

Re: Reserve a value in a serial type field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx

Get Sheeky @ http://Sheeky.Biz


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux