Received: from as104.tel.hr (as104.tel.hr [205.219.255.36]) by hub.org (8.10.1/8.10.1) with ESMTP id e8B73hf25293 for ; Mon, 11 Sep 2000 03:03:43 -0400 (EDT) Received: from proxyplus.universe (ao1-m122.tel.hr [195.29.32.122]) by as104.tel.hr (0.0.0/0.0.0) with ESMTP id JAA85847; Mon, 11 Sep 2000 09:03:39 +0200 (MEST) Received: from 192.168.0.1 by Proxy+; Mon, 11 Sep 2000 07:04:38 GMT Message-Id: <4.1.20000911090110.018637e0@192.168.0.7> X-Sender: zeljko@192.168.0.7 X-Mailer: QUALCOMM Windows Eudora Pro Version 4.1 Date: Mon, 11 Sep 2000 09:03:07 +0200 To: Mark Dzmura , "pgsql-interfaces@postgreSQL.org" From: Zeljko Trogrlic Subject: Re: obtaining primary key/rowid following insert, redux... In-Reply-To: <39B70836.94523C33@digital-mission.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200009/33 nextval() is the solution to your problems. currval() won't help, all users will get same previous value. At 05:15 7.9.2000 , Mark Dzmura wrote: >Peter: > >Trying to solve my problem mentioned in the email of half an hour ago, I >searched >through the archives of the interface list and found some of your replies >suggesting >using "currval()" to get the last value assigned from a sequence... However, >here's what happens in a good database with multiple in-use sequences: > >db=# select currval('foo_foo_id_seq'); >ERROR: foo_foo_id_seq.currval is not yet defined in this session > >As an alternative, I discovered that I can get the value this way: > >db=# select last_value from foo_foo_id_seq; >last_value >--------- > 27 > >My questions are, (1) why does the currval() approach give the error >message, and >(2) is it OK to use my alternative?? > >Finally, as far as I can tell, there is a real race condition problem here >in a multiple-connection >scenario (e.g. another task can cause the sequence to be incremented between >the insert >and the select) - but wrapping a transaction around the insert and select >should >take care of it... Thoughts?? > >Thanks, >Mark Dzmura > >