Re: [SQL] Serial numbers

From: Vadim Mikheev <vadim(at)krs(dot)ru>
To: Marcus Better <marcusb(at)matematik(dot)su(dot)se>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Serial numbers
Date: 1999-01-28 09:30:58
Message-ID: 36B02E52.8E61CD44@krs.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Marcus Better wrote:
>
> Herouth Maoz writes:
>
> > So, the inserts for the ccats table become:
> >
> > INSERT INTO ccats (cid, catid) VALUES (currval( 'name of seq' ), 5 );
>
> What if someone does another INSERT between the two INSERTs, then the
> number generator is stepped and the second table gets the wrong serial
> number. Should one use LOCK here?

No!
man create_sequence:

The function currval ('sequence_name') may be used to re-
fetch the number returned by the last call to nextval for
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the specified sequence in the current session. NOTE: cur-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
rval will return an error if nextval has never been called
for the given sequence in the current backend session.
Also beware that it does not give the last number ever
allocated, only the last one allocated by this backend.

I.e. - CURRVAL is not affected by concurrent NEXVALs...

Vadim

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message The Hermit Hacker 1999-01-28 10:05:06 Test ...
Previous Message Marcus Better 1999-01-28 09:12:56 Serial numbers