Re: arbitrary number of values from a sequence

From: "Eric G(dot) Miller" <egm2(at)jps(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: arbitrary number of values from a sequence
Date: 2001-05-05 13:13:06
Message-ID: 20010505061306.A25928@calico.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)jps(dot)net>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christian Marschalek 2001-05-05 13:15:15 RE: [ADMIN] Primary Keys
Previous Message Gyozo Papp 2001-05-05 12:33:22 Re: arbitrary number of values from a sequence