Home » U++ Library support » U++ SQL » PostgreSQL GetInsertedId()
PostgreSQL GetInsertedId() [message #16618] |
Wed, 02 July 2008 16:34 |
captainc
Messages: 278 Registered: December 2006 Location: New Jersey, USA
|
Experienced Member |
|
|
I noticed the problem with PostgreSQL's GetInsertedId(). I found this post on the web:
Quote: | I would always suggest that people do a select nextval('seq') followed by a suitable insert. It requires no locking, is definitely multi user safe and will *always* correctly identify the row. The only downside is that it requires a quick select before the insert, but if this minor speed sacrifice was that much of an issue"
|
The definition of nextval() from postgres site:
"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."
This means that you would have to use the value returned in the insert statement.
Also, currval() should be session-safe, and is probably easier to use.
Like the mysql package, maybe we can use a 'lastid' variable and update the id for each insert statement made.
Otherwise, we might need a 'lastsequence' variable and a String GetLastSequence() function, and as the source comments suggest, a GetInsertedId(const char* sequence) function to go along with it.
Then we could make the call sqlGetInsertedId(sql.GetLastSequence()).
Thoughts?
[Updated on: Wed, 02 July 2008 17:02] Report message to a moderator
|
|
|
|
|
PostgreSQL GetInsertedId()
|
|
|
Re: PostgreSQL GetInsertedId()
|
|
|
Re: PostgreSQL GetInsertedId()
By: mirek on Wed, 02 July 2008 23:17
|
|
|
Re: PostgreSQL GetInsertedId()
|
|
|
Re: PostgreSQL GetInsertedId()
By: mirek on Fri, 04 July 2008 13:49
|
|
|
Re: PostgreSQL GetInsertedId()
|
|
|
Re: PostgreSQL GetInsertedId()
By: unodgs on Mon, 07 July 2008 22:15
|
|
|
Re: PostgreSQL GetInsertedId()
By: mirek on Mon, 07 July 2008 22:17
|
|
|
Re: PostgreSQL GetInsertedId()
By: unodgs on Mon, 07 July 2008 22:46
|
|
|
Re: PostgreSQL GetInsertedId()
By: zsolt on Mon, 07 July 2008 22:49
|
|
|
Re: PostgreSQL GetInsertedId()
By: mirek on Tue, 08 July 2008 07:22
|
|
|
Re: PostgreSQL GetInsertedId()
By: zsolt on Tue, 08 July 2008 08:55
|
|
|
Re: PostgreSQL GetInsertedId()
By: zsolt on Mon, 07 July 2008 22:48
|
|
|
Re: PostgreSQL GetInsertedId()
By: mirek on Tue, 08 July 2008 15:57
|
|
|
Re: PostgreSQL GetInsertedId()
By: zsolt on Tue, 08 July 2008 16:56
|
|
|
Re: PostgreSQL GetInsertedId()
|
Goto Forum:
Current Time: Sun Apr 28 15:44:51 CEST 2024
Total time taken to generate the page: 0.02749 seconds
|