summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/postgres.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2005-10-22 05:24:30 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2005-10-22 05:24:30 +0000
commit4997a5d60ada68cd18b0c6aad35a3d744a5b07ee (patch)
tree8a70680f26711430ed9294e22b063582b951d20f /lib/sqlalchemy/databases/postgres.py
parentdff6373d43a71f36f46d0917639d39299106f94a (diff)
downloadsqlalchemy-4997a5d60ada68cd18b0c6aad35a3d744a5b07ee.tar.gz
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r--lib/sqlalchemy/databases/postgres.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index a4361af67..4b20fd57f 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -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