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

From: Philippe Ferreira <phil(dot)f(at)worldonline(dot)fr>
To: jim(at)contactbda(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: My very first PL/pgSQL procedure...
Date: 2006-01-26 20:04:25
Message-ID: 43D92B49.8060809@worldonline.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bob Pawley 2006-01-26 20:06:38 Re: Arrays
Previous Message Stephan Szabo 2006-01-26 19:43:36 Re: Arrays