On Tue, Nov 27, 2007 at 01:13:13PM -0700, m h wrote:
On Nov 27, 2007 12:18 PM, Niels Nes
wrote: On Tue, Nov 27, 2007 at 08:16:30PM +0100, Martin Kersten wrote:
Great. Is there a way to ask sequences for the previous value? Or is it only next?
only next.
So if I use SERIAL or AUTOINCREMENT columns, what is the way to get the most recently inserted ID? (Am assumming it's not possible?)
how about a max() over the column?
how about concurrent inserts ;-(
Thanks much for the responses.
Sorry to beat a dead horse.... (Am currently in the process of simulating AUTOINC and SERIAL with SEQUENCES as suggested, since the ORM part of SQLAlchemy relies heavily on knowing the id).
So let me rephrase my question to try to eliminate the concurrency issue. Is is possible to get the ID of the item I recently inserted (ignoring that others might have inserted them). Perhaps the concurrency can't be eliminated here, since the cursor doesn't know the id, it's all server side.
well, maybe not quite want you want/expect, but how about: if the item (tuple) has a key other than the autoinc/serial/... ID, just lookup the item by this key (tha you know since you inserted it) and project on the ID. This is not "elegant" at all, there are now performance "guarantees, but it's purely non-procedural very basic SQL... Stefan
Hope I'm not being too annoying, I'm just trying to understand how things work.
-- | Dr. Stefan Manegold | mailto:Stefan.Manegold@cwi.nl | | CWI, P.O.Box 94079 | http://www.cwi.nl/~manegold/ | | 1090 GB Amsterdam | Tel.: +31 (20) 592-4212 | | The Netherlands | Fax : +31 (20) 592-4312 |