Re: lastrowid not correct?
"Nicholas Bastin" <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Jul 24, 2008 at 10:03 PM, James Henstridge <[email protected]> wrote: > The psycopg2 code looks like it is supposed to set the lastrowid > attribute to the result of PQoidValue() here. This will be different > to SERIAL sequence ID, so is probably not what you are after. > > In Storm, we do the following: > > 1. if PostgreSQL >= 8.2 is in use, use a query like the following: > INSERT INTO Reports (uuid, path) VALUES (x, y) RETURNING Reports.id > > This way the INSERT statement generates a result set with column > values from the row that has just been inserted. > > 2. For older PostgreSQL versions, issue a query like: > SELECT currval(Reports_id_seq); > > To find out what the current value of the sequence is right after the insert. > > > If you know you won't be using an old version of PostgreSQL, then the > first version is preferable, since it involves only a single query. Learn something new every day. :-) Thanks for the help, the first example works great. -- Nick