X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 099D830DBD7 for ; Wed, 18 Jun 2003 13:41:56 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 48900-10 for ; Wed, 18 Jun 2003 10:41:45 -0300 (ADT) Received: from mail.virginia.edu (mail.Virginia.EDU [128.143.2.9]) by svr1.postgresql.org (Postfix) with SMTP id 3B6A930DBF6 for ; Wed, 18 Jun 2003 10:41:43 -0300 (ADT) Received: from smtp.mail.virginia.edu by mail.virginia.edu id aa26757; 18 Jun 2003 9:41 EDT Received: from virginia.edu (d-128-19-222.bootp.Virginia.EDU [128.143.19.222]) by smtp.mail.Virginia.EDU (8.11.7/8.11.6) with ESMTP id h5IDfgl36350; Wed, 18 Jun 2003 09:41:42 -0400 Message-ID: <3EF06E06.7010509@virginia.edu> Date: Wed, 18 Jun 2003 09:49:58 -0400 From: Jodi Kanter User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 To: Bruno Wolff III Cc: Postgres Admin List Subject: Re: psql sequence question References: <3EEDE12C.30401@virginia.edu> <20030616160410.GA29057@wolff.to> Content-Type: multipart/alternative; boundary="------------010709070908030804080506" X-Archive-Number: 200306/219 X-Sequence-Number: 9210 --------------010709070908030804080506 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit so it sounds like I just need to tell my programmer friend to change his use of last value to currval instead? I just hate silly mistakes like this! Thanks for the help. Jodi Bruno Wolff III wrote: >On Mon, Jun 16, 2003 at 11:24:28 -0400, > Jodi Kanter wrote: > >>If I'm using transactions (not autocommit), are sequences atomic? >> > >Yes. > >>In other words, after inserting a record to a table that >>uses sequence A, am I guaranteed that select last_value on >>sequence A is atomic, and cannot be interfered with by other >>transactions using that same sequence? Sequence A is used by >>several tables. >> > >Probably not in the way you mean. Every transaction is going to see >a consistant view of the sequence table. However transactions proceeding >in parallel may seem the same value for the last value. To make this >work you would need to use serializable mode to do any updates based >on the value of the last value or lock the table exclusively to prevent >concurrent updates. This defeats the function of sequences providing >unique values using light weight locking. > >The right way to use sequences is to use nextval to get new values >and use currval to reuse the value you got from the latest call to >nextval in the same session. > >---------------------------(end of broadcast)--------------------------- >TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org > -- _______________________________ Jodi L Kanter BioInformatics Database Administrator University of Virginia (434) 924-2846 jkanter@virginia.edu --------------010709070908030804080506 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit so it sounds like I just need to tell my programmer friend to change his use of last value to currval instead?
I just hate silly mistakes like this! Thanks for the help.
Jodi


Bruno Wolff III wrote:
On Mon, Jun 16, 2003 at 11:24:28 -0400,
Jodi Kanter <jkanter@virginia.edu> wrote:
If I'm using transactions (not autocommit), are sequences atomic?

Yes.

In other words, after inserting a record to a table that 
uses sequence A, am I guaranteed that select last_value on
sequence A is atomic, and cannot be interfered with by other
transactions using that same sequence? Sequence A is used by
several tables.

Probably not in the way you mean. Every transaction is going to see
a consistant view of the sequence table. However transactions proceeding
in parallel may seem the same value for the last value. To make this
work you would need to use serializable mode to do any updates based
on the value of the last value or lock the table exclusively to prevent
concurrent updates. This defeats the function of sequences providing
unique values using light weight locking.

The right way to use sequences is to use nextval to get new values
and use currval to reuse the value you got from the latest call to
nextval in the same session.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

--
________________________________

_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu


 

 

 


--------------010709070908030804080506--