diff options
author | Johannes Hoppe <info@johanneshoppe.com> | 2019-07-24 08:42:41 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-09-09 10:51:14 +0200 |
commit | 7254f1138d9c51fa558229c39c9559b369c4278a (patch) | |
tree | fc375187018082446c90deb772ac3ce96406c13b /django/db/backends/postgresql/operations.py | |
parent | 736e7d44de395b867011ff9237dc5fdcfd28ee66 (diff) | |
download | django-7254f1138d9c51fa558229c39c9559b369c4278a.tar.gz |
Refs #29444 -- Allowed returning multiple fields from INSERT statements on PostgreSQL.
Thanks Florian Apolloner, Tim Graham, Simon Charette, Nick Pope, and
Mariusz Felisiak for reviews.
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r-- | django/db/backends/postgresql/operations.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index 61bac5e55a..fe5b208c6a 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -76,13 +76,12 @@ class DatabaseOperations(BaseDatabaseOperations): def deferrable_sql(self): return " DEFERRABLE INITIALLY DEFERRED" - def fetch_returned_insert_ids(self, cursor): + def fetch_returned_insert_rows(self, cursor): """ Given a cursor object that has just performed an INSERT...RETURNING - statement into a table that has an auto-incrementing ID, return the - list of newly created IDs. + statement into a table, return the tuple of returned data. """ - return [item[0] for item in cursor.fetchall()] + return cursor.fetchall() def lookup_cast(self, lookup_type, internal_type=None): lookup = '%s' @@ -236,8 +235,16 @@ class DatabaseOperations(BaseDatabaseOperations): return cursor.query.decode() return None - def return_insert_id(self, field): - return "RETURNING %s", () + def return_insert_columns(self, fields): + if not fields: + return '', () + columns = [ + '%s.%s' % ( + self.quote_name(field.model._meta.db_table), + self.quote_name(field.column), + ) for field in fields + ] + return 'RETURNING %s' % ', '.join(columns), () def bulk_insert_sql(self, fields, placeholder_rows): placeholder_rows_sql = (", ".join(row) for row in placeholder_rows) |