Skip to content

Commit 4e4f2ef

Browse files
committed
django: fixed power operator (^)
The tests remain commented out because issue #331 also affects them. fixes #333
1 parent 8018a3f commit 4e4f2ef

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

django_spanner/features.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
257257
# https://github.com/orijtech/django-spanner/issues/331
258258
'expressions.tests.ExpressionOperatorTests.test_lefthand_division',
259259
'expressions.tests.ExpressionOperatorTests.test_right_hand_division',
260-
# power operator doesn't work:
261-
# https://github.com/orijtech/django-spanner/issues/333
260+
# power operator produces a float result, which can't be assigned to
261+
# an integer column:
262+
# https://github.com/orijtech/django-spanner/issues/331
262263
'expressions.tests.ExpressionOperatorTests.test_lefthand_power',
263264
'expressions.tests.ExpressionOperatorTests.test_righthand_power',
264265
# Cloud Spanner's docs: "The rows that are returned by LIMIT and OFFSET

django_spanner/operations.py

+2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ def format_for_duration_arithmetic(self, sql):
214214
def combine_expression(self, connector, sub_expressions):
215215
if connector == '%%':
216216
return 'MOD(%s)' % ', '.join(sub_expressions)
217+
elif connector == '^':
218+
return 'POWER(%s)' % ', '.join(sub_expressions)
217219
return super().combine_expression(connector, sub_expressions)
218220

219221
def combine_duration_expression(self, connector, sub_expressions):

0 commit comments

Comments
 (0)