summaryrefslogtreecommitdiff
path: root/django/db/backends/base/operations.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2025-03-21 21:50:54 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2025-08-28 20:44:21 +0200
commit292b9e6fe8f23491680d9cc60f328562e2b1c823 (patch)
tree73aab051ae88301c5911c60a69bb8e290b0a4c27 /django/db/backends/base/operations.py
parentdc4ee9915228238bd24ce67645504f65eaf2f1fd (diff)
Refs #27222 -- Adapted RETURNING handling to be usable for UPDATE queries.
Renamed existing methods and abstractions used for INSERT … RETURNING to be generic enough to be used in the context of UPDATEs as well. This also consolidates SQL compliant implementations on BaseDatabaseOperations.
Diffstat (limited to 'django/db/backends/base/operations.py')
-rw-r--r--django/db/backends/base/operations.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
index f1b0c09abd..16a6296f9b 100644
--- a/django/db/backends/base/operations.py
+++ b/django/db/backends/base/operations.py
@@ -208,13 +208,6 @@ class BaseDatabaseOperations:
else:
return ["DISTINCT"], []
- def fetch_returned_insert_columns(self, cursor, returning_params):
- """
- Given a cursor object that has just performed an INSERT...RETURNING
- statement into a table, return the newly created data.
- """
- return cursor.fetchone()
-
def force_group_by(self):
"""
Return a GROUP BY clause to use with a HAVING clause when no grouping
@@ -358,11 +351,12 @@ class BaseDatabaseOperations:
"""
return value
- def return_insert_columns(self, fields):
+ def returning_columns(self, fields):
"""
- For backends that support returning columns as part of an insert query,
- return the SQL and params to append to the INSERT query. The returned
- fragment should contain a format string to hold the appropriate column.
+ For backends that support returning columns as part of an insert or
+ update query, return the SQL and params to append to the query.
+ The returned fragment should contain a format string to hold the
+ appropriate column.
"""
if not fields:
return "", ()
@@ -376,10 +370,10 @@ class BaseDatabaseOperations:
]
return "RETURNING %s" % ", ".join(columns), ()
- def fetch_returned_insert_rows(self, cursor):
+ def fetch_returned_rows(self, cursor, returning_params):
"""
- Given a cursor object that has just performed an INSERT...RETURNING
- statement into a table, return the tuple of returned data.
+ Given a cursor object for a DML query with a RETURNING statement,
+ return the selected returning rows of tuples.
"""
return cursor.fetchall()