Use "insert ... returning id" with postgres
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
When inserting records with driver postgres, it's faster to use the single statement "INSERT ... RETURNING id",
rather than 2 statements -- one to get the current sequence value (and increment it), and another to do the insert.
Patch is against SQLObject-1.2.4/sqlobject/postgres/pgconnection.py.
Good idea, thanks! Will test it. It's a major change (SQLObject currently supports Postgres back to 8.1 while INSERT/RETURNING requires at least 8.2) so I can only apply it to the trunk.
I have to work on the patch. There were two problems. First, it was created against branch 1.2 and I have to modify it to apply to the trunk. Second, it creates a possibility for an INSERT without columns in case like
SQLObject has never had a need to handle such a case — at least the id column was always there. With your patch SQLObject has to generate query "INSERT INTO table DEFAULT VALUES" instead of "INSERT INTO table () VALUES ()".
Now everything works. Applied and committed in the revision 4574 in the trunk. Will be in the next release. Thank you!