Re: arbitrary number of values from a sequence

Поиск
Список
Период
Сортировка
От Eric G. Miller
Тема Re: arbitrary number of values from a sequence
Дата
Msg-id 20010505061306.A25928@calico.local
обсуждение исходный текст
Ответ на Re: arbitrary number of values from a sequence  ("Gyozo Papp" <pgerzson@freestart.hu>)
Список pgsql-general
On Sat, May 05, 2001 at 02:33:22PM +0200, Gyozo Papp wrote:
> Ok. I'm looking for another solution.
>
> The reason why I'm not dealing with sequence's increment is that
> there is no way to set an appropiate limit, sometimes I need 5, sometimes 17.

CREATE TABLE myseq (
    val  integer NOT NULL;
);

psuedocode:

func (integer howmany)
    ...
    BEGIN TRANSACTION;
    oldval := SELECT val FROM myseq FOR UPDATE;
    newval := oldval + howmany;
    UPDATE myseq SET val = newval;
    COMMIT;

    for i := oldval; i < newval; incr i
        do stuff

    ...

You might want to use LOCK instead of FOR UPDATE since its behavior
depends on the TRANSACTION ISOLATION LEVEL.

--
Eric G. Miller <egm2@jps.net>

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

Предыдущее
От: "Gyozo Papp"
Дата:
Сообщение: Re: arbitrary number of values from a sequence
Следующее
От: "Christian Marschalek"
Дата:
Сообщение: RE: [ADMIN] Primary Keys