pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSerial numbers
3+ messages / 2 participants
[nested] [flat]
* Serial numbers
@ 1999-01-28 09:12 Marcus Better <marcusb@matematik.su.se>
1999-01-28 09:30 ` Re: [SQL] Serial numbers Vadim Mikheev <vadim@krs.ru>
0 siblings, 1 reply; 3+ messages in thread
From: Marcus Better @ 1999-01-28 09:12 UTC (permalink / raw)
To: pgsql-sql
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?
Marcus
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] Serial numbers
1999-01-28 09:12 Serial numbers Marcus Better <marcusb@matematik.su.se>
@ 1999-01-28 09:30 ` Vadim Mikheev <vadim@krs.ru>
1999-01-28 10:49 ` Re: [SQL] Serial numbers Marcus Better <marcusb@matematik.su.se>
0 siblings, 1 reply; 3+ messages in thread
From: Vadim Mikheev @ 1999-01-28 09:30 UTC (permalink / raw)
To: Marcus Better <marcusb@matematik.su.se>; +Cc: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] Serial numbers
1999-01-28 09:12 Serial numbers Marcus Better <marcusb@matematik.su.se>
1999-01-28 09:30 ` Re: [SQL] Serial numbers Vadim Mikheev <vadim@krs.ru>
@ 1999-01-28 10:49 ` Marcus Better <marcusb@matematik.su.se>
0 siblings, 0 replies; 3+ messages in thread
From: Marcus Better @ 1999-01-28 10:49 UTC (permalink / raw)
To: Vadim Mikheev <vadim@krs.ru>; +Cc: pgsql-sql
> 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-
Ah. Missed that part :) Thanks.
Marcus
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1999-01-28 10:49 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-01-28 09:12 Serial numbers Marcus Better <marcusb@matematik.su.se>
1999-01-28 09:30 ` Vadim Mikheev <vadim@krs.ru>
1999-01-28 10:49 ` Marcus Better <marcusb@matematik.su.se>
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