]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Oct 2005 05:24:30 +0000 (05:24 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Oct 2005 05:24:30 +0000 (05:24 +0000)
lib/sqlalchemy/databases/postgres.py

index a4361af6771a692722548a5ded031b8608245d08..4b20fd57f83ba5b4dceee62f562ff78679ace49b 100644 (file)
@@ -96,6 +96,7 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
 
     def pre_exec(self, connection, cursor, statement, parameters, echo = None, compiled = None, **kwargs):
         if True: return
+        # if a sequence was explicitly defined we do it here
         if compiled is None: return
         if getattr(compiled, "isinsert", False):
             last_inserted_ids = []
@@ -113,7 +114,12 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
     def post_exec(self, connection, cursor, statement, parameters, echo = None, compiled = None, **kwargs):
         if compiled is None: return
         if getattr(compiled, "isinsert", False):
-            self.context.last_inserted_ids = [cursor.lastrowid]
+            # psycopg wants to make it hard on us and give us an OID.  well, pre-select a sequence,
+            # or post-select the row, I guess not much diff.
+            table = compiled.statement.table
+            if len(table.primary_keys):
+                row = sql.select(table.primary_keys, sql.ColumnClause("oid",table) == bindparam('oid', cursor.lastrowid) ).execute().fetchone()
+                self.context.last_inserted_ids = [v for v in row]
 
     def dbapi(self):
         return self.module