Re: Design question regarding arrays

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Design question regarding arrays
Дата
Msg-id 20040809071805.X32884@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Re: Design question regarding arrays  (Oliver Fromme <olli@lurza.secnetix.de>)
Список pgsql-novice
On Mon, 9 Aug 2004, Oliver Fromme wrote:

> Sean Davis wrote:
>  > I'm a novice, too, but why not look up the value in the sequence and
>  > increment it before doing any inserting?  If you are doing all the inserts
>  > at the same time (more or less), then you can just use this value in the
>  > insert into both tables.  Put all of this inside one transaction.
>
> That won't work if another process is trying to do the same
> thing at the same time.  They both get the same value when
> they look it up, so there will be an ID collision.

It should be safe if you're using a sequence and using nextval() to get
the value that you are using in both insert statements. A second session
will not get the same value you just got from nextval barring a cycling
sequence generator that wraps back to the same number between the nextval
and insert.

В списке pgsql-novice по дате отправления:

Предыдущее
От: Oliver Fromme
Дата:
Сообщение: Re: Design question regarding arrays
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Multiple return 'columns' from postgre pl/pgsql