Re: My very first PL/pgSQL procedure...

Поиск
Список
Период
Сортировка
От Philippe Ferreira
Тема Re: My very first PL/pgSQL procedure...
Дата
Msg-id 43D92B49.8060809@worldonline.fr
обсуждение исходный текст
Ответ на Re: My very first PL/pgSQL procedure...  ("Jim Buttafuoco" <jim@contactbda.com>)
Ответы Re: My very first PL/pgSQL procedure...  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
> why not just use setval(), see docs for arguments.


I think that "setval('seq_name', xx)" have the same effect than
"SEQUENCE seq_name RESTART WITH xx" (the instruction I
wanted to use in my first function).

But the problem is that in both cases, the sequence should be
locked in order to prevent problems with concurrent transactions.
For example, if I want to raise the sequence value to "1000", while
its current value is "998", I would call :
     setval('seq_name', 1000);

But because the sequence could not be locked, some concurrent
transactions could have already raised it's current value in the
meantime to, say, "1002", before the effective execution of setval().

So, instead of raising the value to 1000, my function could have
done the opposite (from 1002 to 1000) ! And the two next "INSERT"
using this sequence would then break !!

The only solution I found to prevent this is with my "loops" !!

Best regards,
Philippe Ferreira.

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

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Arrays
Следующее
От: "Oisin Glynn"
Дата:
Сообщение: VACUUM Question