summaryrefslogtreecommitdiff
path: root/django/db/backends
diff options
context:
space:
mode:
authorManuel Weitzman <manuelweitzman@gmail.com>2020-05-10 12:25:06 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-21 10:51:10 +0200
commita4e6030904df63b3f10aa0729b86dc6942b0458e (patch)
tree7a84def5f8bd0e0376a471fa238f74f429e25478 /django/db/backends
parent0e893248b28e30bf562d29e6d5745ffad4b1a1eb (diff)
Fixed #30375 -- Added FOR NO KEY UPDATE support to QuerySet.select_for_update() on PostgreSQL.
Diffstat (limited to 'django/db/backends')
-rw-r--r--django/db/backends/base/features.py1
-rw-r--r--django/db/backends/base/operations.py5
-rw-r--r--django/db/backends/postgresql/features.py1
3 files changed, 5 insertions, 2 deletions
diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py
index 35ce3ba299..31113e1c7a 100644
--- a/django/db/backends/base/features.py
+++ b/django/db/backends/base/features.py
@@ -38,6 +38,7 @@ class BaseDatabaseFeatures:
has_select_for_update_nowait = False
has_select_for_update_skip_locked = False
has_select_for_update_of = False
+ has_select_for_no_key_update = False
# Does the database's SELECT FOR UPDATE OF syntax require a column rather
# than a table?
select_for_update_of_column = False
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
index 6d0f5c68b3..2e283a3193 100644
--- a/django/db/backends/base/operations.py
+++ b/django/db/backends/base/operations.py
@@ -207,11 +207,12 @@ class BaseDatabaseOperations:
"""
return []
- def for_update_sql(self, nowait=False, skip_locked=False, of=()):
+ def for_update_sql(self, nowait=False, skip_locked=False, of=(), no_key=False):
"""
Return the FOR UPDATE SQL clause to lock rows for an update operation.
"""
- return 'FOR UPDATE%s%s%s' % (
+ return 'FOR%s UPDATE%s%s%s' % (
+ ' NO KEY' if no_key else '',
' OF %s' % ', '.join(of) if of else '',
' NOWAIT' if nowait else '',
' SKIP LOCKED' if skip_locked else '',
diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py
index a4ba0b99fc..f8d2ea1286 100644
--- a/django/db/backends/postgresql/features.py
+++ b/django/db/backends/postgresql/features.py
@@ -18,6 +18,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
has_select_for_update_nowait = True
has_select_for_update_of = True
has_select_for_update_skip_locked = True
+ has_select_for_no_key_update = True
can_release_savepoints = True
supports_tablespaces = True
supports_transactions = True