db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Eade <se...@backstagetech.com.au>
Subject Re: Problem w/PostgreSQL Insert
Date Wed, 18 Feb 2004 21:00:36 GMT
Sean Laurent wrote:

>I appreciate the response, Scott.  However, with all due respect, you're 
>To demonstrate this, I created a simple project which contained a single table 
>with two columns: an autoincrement primary key and a value (type double).  
>Initially, the table was completely empty.  After initializing Torque, I 
>created a new object, set the value and attempted to save it.  I got the 
>following error:
>  org.postgresql.util.PSQLException: ERROR: currval of sequence "mytest_seq" 
>is not yet defined in this session
Can you please post the schema you used for this demonstration.  I am 
curious to know if you are telling torque the name of the sequence to 
use (I suspect not).

Have you read the following?


>Second, I stepped through the entire code and you are partially correct: the 
>attempt to retrieve the current sequence value occurs after the insert.  
>However, the insert has not technically completed, since it's wrapped in a 
>Under the hood, the insert should be triggering a call nextval() inside 
>PostgreSQL.  Unfortunately, something still doesn't work correctly.  I have a 
>couple of guesses, but I'm not certain which, if any, are correct.  It could 
>be because the insert and the call to currval are all wrapped in the one 
>giant transaction.  It could be because the automatic trigger to nextval() is 
>technically in a different session.  I'm not certain.
>Regardless, the end result is that the call to currval() always fails.  I 
>refer you to section 9.11 Sequence-Manipulation Functions in the PostgreSQL 
>7.4 documentation:
>Advance the sequence object to its next value and return that value. This is 
>done atomically: even if multiple sessions execute nextval concurrently, each 
>will safely receive a distinct sequence value.
>Return the value most recently obtained by nextval for this sequence in the 
>current session. (An error is reported if nextval has never been called for 
>this sequence in this session.) Notice that because this is returning a 
>session-local value, it gives a predictable answer even if other sessions are 
>executing nextval meanwhile.
>Please notice that concurrency is not an issue when calling nextval().  The 
>easiest solution is simply to call nextval() instead of currval() in 
You are probably right - it most likely just dishes out sequence values 
ignoring whether or not they are actually used, thus no concurrency issue.

>So, I respectfully would like to know what I need to do help get this fixed in 
>the main code base.  I've already modified my own copy of Torque, but I would 
>prefer to see this fixed everywhere.  Your assistance would be greatly 
I use PostgreSQL as my primary database server and would thus be very 
surprised if this turns out to be an issue.


Scott Eade
Backstage Technologies Pty. Ltd.

To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message