Skip to content

Commit

Permalink
Refs #35295 -- Added BaseDatabaseOperations.bulk_insert_sql().
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Pope <[email protected]>
  • Loading branch information
felixxm and ngnpope committed Mar 14, 2024
1 parent 95ae378 commit 912f72a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
5 changes: 5 additions & 0 deletions django/db/backends/base/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def limit_offset_sql(self, low_mark, high_mark):
if sql
)

def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join([f"({sql})" for sql in placeholder_rows_sql])
return f"VALUES {values_sql}"

def last_executed_query(self, cursor, sql, params):
"""
Return a string of the query last executed by the given cursor, with
Expand Down
5 changes: 0 additions & 5 deletions django/db/backends/mysql/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,6 @@ def max_name_length(self):
def pk_default_value(self):
return "NULL"

def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
return "VALUES " + values_sql

def combine_expression(self, connector, sub_expressions):
if connector == "^":
return "POW(%s)" % ",".join(sub_expressions)
Expand Down
5 changes: 0 additions & 5 deletions django/db/backends/postgresql/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,6 @@ def return_insert_columns(self, fields):
]
return "RETURNING %s" % ", ".join(columns), ()

def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
return "VALUES " + values_sql

if is_psycopg3:

def adapt_integerfield_value(self, value, internal_type):
Expand Down
5 changes: 0 additions & 5 deletions django/db/backends/sqlite3/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,6 @@ def convert_uuidfield_value(self, value, expression, connection):
def convert_booleanfield_value(self, value, expression, connection):
return bool(value) if value in (1, 0) else value

def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join(f"({sql})" for sql in placeholder_rows_sql)
return f"VALUES {values_sql}"

def combine_expression(self, connector, sub_expressions):
# SQLite doesn't have a ^ operator, so use the user-defined POWER
# function that's registered in connect().
Expand Down

0 comments on commit 912f72a

Please sign in to comment.