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 <[EMAIL PROTECTED]>

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Reply via email to