Re: Autoincremental value

Поиск
Список
Период
Сортировка
От Pierre-Frédéric Caillaud
Тема Re: Autoincremental value
Дата
Msg-id opscv2n6p6cq72hf@musicbox
обсуждение исходный текст
Ответ на Re: Autoincremental value  (adburne@asocmedrosario.com.ar)
Ответы Re: Autoincremental value  ("Scott Marlowe" <smarlowe@qwest.net>)
Список pgsql-general
    Suppose your table is like :

    key1    key2
    1    1
    1    2
    2    1

    To get the next value to insert for key1=1 you can do this :

    SELECT key2 FROM ... WHERE key1=1 ORDER BY key2 DESC LIMIT 1

    Of course a UNIQUE INDEX on key1, key2 helps.

    You won't be protected from two transactions adding the same value at the
same time, though. The unique index will catch them and one of them will
fail (constraint violation etc). Just retry the transaction until it
works... or, be a warrior and lock the table... but if you do that, please
do it in a function/trigger so that it's not kept locked for long !


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

Предыдущее
От: "Gavin M. Roy"
Дата:
Сообщение: Re: PANIC: btree_split_redo: lost left sibling?
Следующее
От: Pierre-Frédéric Caillaud
Дата:
Сообщение: Re: Web application: Programming language/Framework