pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vadim Mikheev <vadim@krs.ru>
To: Marcus Better <marcusb@matematik.su.se>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Serial numbers
Date: Thu, 28 Jan 1999 16:30:58 +0700
Message-ID: <36B02E52.8E61CD44@krs.ru> (raw)
References: <14000.10525.469359.464174@unreal.matematik.su.se>

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



view thread (3+ messages)  latest in thread

Message-ID: <36B02E52.8E61CD44@krs.ru>
Permalink:  ../36B02E52.8E61CD44@krs.ru/
Also on:    postgresql.org/message-id/36B02E52.8E61CD44@krs.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: vadim@krs.ru, marcusb@matematik.su.se
  Subject: Re: [SQL] Serial numbers
  In-Reply-To: <36B02E52.8E61CD44@krs.ru>
  References: <14000.10525.469359.464174@unreal.matematik.su.se> <36B02E52.8E61CD44@krs.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox