|
@@ -3,6 +3,7 @@ from functools import lru_cache, partial
|
|
|
|
|
|
from django.conf import settings
|
|
|
from django.db.backends.base.operations import BaseDatabaseOperations
|
|
|
+from django.db.backends.postgresql.compiler import InsertUnnest
|
|
|
from django.db.backends.postgresql.psycopg_any import (
|
|
|
Inet,
|
|
|
Jsonb,
|
|
@@ -24,6 +25,7 @@ def get_json_dumps(encoder):
|
|
|
|
|
|
|
|
|
class DatabaseOperations(BaseDatabaseOperations):
|
|
|
+ compiler_module = "django.db.backends.postgresql.compiler"
|
|
|
cast_char_field_without_max_length = "varchar"
|
|
|
explain_prefix = "EXPLAIN"
|
|
|
explain_options = frozenset(
|
|
@@ -148,6 +150,11 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|
|
def deferrable_sql(self):
|
|
|
return " DEFERRABLE INITIALLY DEFERRED"
|
|
|
|
|
|
+ def bulk_insert_sql(self, fields, placeholder_rows):
|
|
|
+ if isinstance(placeholder_rows, InsertUnnest):
|
|
|
+ return f"SELECT * FROM {placeholder_rows}"
|
|
|
+ return super().bulk_insert_sql(fields, placeholder_rows)
|
|
|
+
|
|
|
def fetch_returned_insert_rows(self, cursor):
|
|
|
"""
|
|
|
Given a cursor object that has just performed an INSERT...RETURNING
|