On Feb 18, 2006, at 12:46 PM, Rick Morrision wrote:

Mike,

PG will give back the value of a newly inserted SERIAL value by calling " SELECT currval('sequencename') ". If this is issued inside the same transaction as the INSERT, it's race-condition free.

thats good to know. we are pre-executing the sequence in general so it works out just as well. the bug was that a condition arose, when you reflected the table and it therefore created a "passive" default (docs upcoming for this concept...) where this pre-execution wasnt occuring. you now can specify the column default as anything you want, not just a sequence, and it still should work, even if its on a primary key. this works in a more general case than using just 'currval' since the column default doesnt even have to be a sequence.

I believe the reason pyscopg doesn't do this to set cursor.lastrowid, is

a) - there may be more than one SERIAL column on the row, and no way to determine which is the "row id"
b) - won't work in autocommit mode

the reason it doesnt work is because by definition, lastrowid is supposed to return an internal "row id" object, not the primary key column. But, postgres deprecated OID as of 8.something, and made it so that tables by default will not have OIDs. they also said, "dont use OIDs", which I believe is because the OID is not big enough to encompass the highest actual row number, and some other reasons you can see if you search the psycopg mailing list.

a couple of links from psycopg:

return only OIDS (I think theyre right, too) :
        http://www.initd.org/tracker/psycopg/ticket/29

still waiting for someone to suggest how a lastrowid should be implemented:
        http://article.gmane.org/gmane.comp.python.db.psycopg.devel/2835

im not exactly sure why postgres cant just fix OID, I would think that rows already have some kind of absolute internal identifier. *shrug*....



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to