Re: Reserve a value in a serial type field

Поиск
Список
Период
Сортировка
От Shane Ambler
Тема Re: Reserve a value in a serial type field
Дата
Msg-id 45ABE0F4.9060004@007Marketing.com
обсуждение исходный текст
Ответ на Reserve a value in a serial type field  ("Albert" <alberto.molteni@libero.it>)
Ответы Re: Reserve a value in a serial type field  ("Albert" <alberto.molteni@libero.it>)
Список 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 по дате отправления:

Предыдущее
От: Oleg Bartunov
Дата:
Сообщение: Re: Avoiding empty queries in tsearch
Следующее
От: "Albert"
Дата:
Сообщение: Re: Reserve a value in a serial type field