Re: [BUGS] probably a bug of data-type serial

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [BUGS] probably a bug of data-type serial
Date: 2001-10-18 18:36:31
Message-ID: 200110181836.OAA11037@smtp6.mindspring.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> This is intentional. If the sequence number were to roll
> back, then a later transaction trying to get the next sequence
> number would have to wait to determine if you've rolled back
> before getting the number. Sequences are defined to try to
> give unique, increasing numbers, not actually sequential ones.

I often have the need for unique, sequential numbers, so I
do the following:

1. Create a table to store the value, usually as an integer column
2. Lock that table in exclusive mode
3. Grab the current value with a select statement
4. Try and do something with the value, usually involving
sticking the value into anoter table
5. If it fails, simply exit
6. If it succeeds, do an update and increase the value by one
7. Commit (and unlock the table)

Question: is this the best way to do this? I am being careful
so nobody accesses the particular table without using the
logic above.

Thanks,
Greg Sabino Mullane
greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200110171428

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iQA/AwUBO88hrLybkGcUlkrIEQKHWACg4oH4zuV40UGDrr3irh20SW/BkmUAoO5W
FpndyZQj7Joj5/6eXA2w35g3
=dIeb
-----END PGP SIGNATURE-----

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2001-10-18 20:34:19 Re: [BUGS] SQLCODE==-209
Previous Message Greg Sabino Mullane 2001-10-18 18:25:37 Re: Showing index details with \d on psql