Re: List last value of all sequences

From: greg(at)turnstep(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Re: List last value of all sequences
Date: 2003-07-24 21:21:17
Message-ID: aa695fccd4f3f2ee39be3abf1a789738@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


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

Stephan Szabo wrote:
> I'm not sure, but if another transaction wanted to do a nextval at "the
> same time" couldn't the sequence of events end up going something like:
>
> T1: nextval
> T2: nextval
> T1: setval(currval-1)

*shrug* It's possible, though perhaps unlikely, as transaction 2 has a /very/
small window in which to wreak its havok. I like the function solution better
anyway; consider the pure SQL one an academic exercise. :)

Berend Tober said:
> I guess nothing beats empirical evidence! I was basing my comments on my
> (mis?)understanding of what the documentation says.

My query should match the docs. I'm getting the next value, which increments
the sequence by one, then I set the sequence to one less than the value I just
grabbed, so it should be back in its initial state. So, we are both correct:
I am changing the value, and it stays the same. Aren't sequences fun? :)

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200307241716

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

iD4DBQE/IE1XvJuQZxSWSsgRApJsAJdha8ZoVJi0QYxRK/2hgnZKLObyAJ4gkBJI
349WNU+i+5j6WttaGcgKtw==
=C0O+
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Douglas Trainor 2003-07-24 21:28:54 Re: How to encrypt data in Postgresql
Previous Message btober 2003-07-24 21:15:19 Re: List last value of all sequences