summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/operations.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r--django/db/backends/postgresql/operations.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 18cfcb29cb..aa839f5634 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -12,6 +12,7 @@ from django.db.backends.postgresql.psycopg_any import (
)
from django.db.backends.utils import split_tzname_delta
from django.db.models.constants import OnConflict
+from django.db.models.functions import Cast
from django.utils.regex_helper import _lazy_re_compile
@@ -413,3 +414,13 @@ class DatabaseOperations(BaseDatabaseOperations):
update_fields,
unique_fields,
)
+
+ def prepare_join_on_clause(self, lhs_table, lhs_field, rhs_table, rhs_field):
+ lhs_expr, rhs_expr = super().prepare_join_on_clause(
+ lhs_table, lhs_field, rhs_table, rhs_field
+ )
+
+ if lhs_field.db_type(self.connection) != rhs_field.db_type(self.connection):
+ rhs_expr = Cast(rhs_expr, lhs_field)
+
+ return lhs_expr, rhs_expr