Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #5030 -- Removed 'COUNT()' from when determining w…

…hether a row exists. We're now using a SELECT 1 LIMIT 1 instead, as it's more efficient in some databases. Thanks, and the various folks who verified this patch works

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 478926f commit 947ca5123e2e88a2226ed3b39711706d5d609e32 @adrianholovaty adrianholovaty committed
Showing with 2 additions and 2 deletions.
  1. +2 −2 django/db/models/
4 django/db/models/
@@ -213,11 +213,11 @@ def save(self, raw=False):
record_exists = True
if pk_set:
# Determine whether a record with the primary key already exists.
- cursor.execute("SELECT COUNT(*) FROM %s WHERE %s=%%s" % \
+ cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \
(backend.quote_name(self._meta.db_table), backend.quote_name(,'exact', pk_val))
# If it does already exist, do an UPDATE.
- if cursor.fetchone()[0] > 0:
+ if cursor.fetchone():
db_values = [f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False)) for f in non_pks]
if db_values:
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \

0 comments on commit 947ca51

Please sign in to comment.
Something went wrong with that request. Please try again.