Author: phd
Date: Sat Jan 19 11:19:02 2013
New Revision: 4574
Log:
Use INSERT...RETURNING id
Optimization in PostgresConnection: use INSERT...RETURNING id
to get the autoincremented id in one query instead of two
(SELECT id + INSERT).
The feature requires PostgreSQL 8.2+.
Modified:
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/postgres/pgconnection.py
Modified: SQLObject/trunk/docs/News.txt
==============================================================================
--- SQLObject/trunk/docs/News.txt Sat Jan 19 11:10:09 2013 (r4573)
+++ SQLObject/trunk/docs/News.txt Sat Jan 19 11:19:02 2013 (r4574)
@@ -10,6 +10,16 @@
SQLObject (trunk)
=================
+Features & Interface
+--------------------
+
+* Support for PostgreSQL 8.1 is dropped. The minimal supported version of
+ PostgreSQL is 8.2 now.
+
+* Optimization in PostgresConnection: use INSERT...RETURNING id
+ to get the autoincremented id in one query instead of two
+ (SELECT id + INSERT).
+
SQLObject 1.3.2
===============
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
==============================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py Sat Jan 19 11:10:09 2013 (r4573)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py Sat Jan 19 11:19:02 2013 (r4574)
@@ -189,15 +189,20 @@
sequenceName = soInstance.sqlmeta.idSequence or \
'%s_%s_seq' % (table, idName)
c = conn.cursor()
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
+ if names and values:
+ q = self._insertSQL(table, names, values)
+ else:
+ q = "INSERT INTO %s DEFAULT VALUES" % table
if id is None:
- self._executeRetry(conn, c, "SELECT NEXTVAL('%s')" % sequenceName)
- id = c.fetchone()[0]
- names = [idName] + names
- values = [id] + values
- q = self._insertSQL(table, names, values)
+ q += " RETURNING " + idName
if self.debug:
self.printDebug(conn, q, 'QueryIns')
self._executeRetry(conn, c, q)
+ if id is None:
+ id = c.fetchone()[0]
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
return id
|