Skip site navigation (1) Skip section navigation (2)

Re: Query inside transaction

From: Ago <ago(at)nmb(dot)it>
To: Michal Táborský <michal(at)taborsky(dot)cz>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query inside transaction
Date: 2004-06-25 10:48:43
Message-ID: 3171012522ago@nmb.it (view raw or flat)
Thread:
Lists: pgsql-general
OK, thanks Michal, I did not know this issue. I thought I should use LOCK table inside the transaction to pick up the correct id value from SELECT MAX(id) FROM e_catalog.


On 25/06/2004 12.38, Michal Táborský <michal(at)taborsky(dot)cz> wrote:
>NMB Webmaster wrote:
>
>> But if someone else runs the same transaction in the same time 
>what 
> > value does "currval('sequence')" return? That one of the first
> > transaction or that one of the other transaction? Moreover, field
> > id is a unique primary key, it does not accept duplicates.
>
>That's the beauty of sequences. They are transaction-safe. Co 
>"currval('sequence')" will always return the same value of the previous 
>
>nextval call within that transaction, no matter how many other 
>transactions picked the numbers in between.
>
>To demonstrate:
>
>Transaction 1                          	Transaction 2
>BEGIN;					--
>nextval('seq') = 1			BEGIN;
>do something..				nextval('seq') = 2
>do something else...			COMMIT;
>currval('seq') = 1
>COMMIT;
>
>-- 
>Michal Taborsky
>http://www.taborsky.cz
>
>
>



Responses

pgsql-general by date

Next:From: Bruno Wolff IIIDate: 2004-06-25 12:54:32
Subject: Re: Query inside transaction
Previous:From: Michal TáborskýDate: 2004-06-25 10:38:50
Subject: Re: Query inside transaction

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group