Skip to content

Commit c2c3c08

Browse files
authored
django: fix power operator
The tests remain commented out because issue #331 also affects them. fixes #333
1 parent ae837de commit c2c3c08

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

packages/django-google-spanner/django_spanner/features.py

Lines changed: 3 additions & 2 deletions
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

packages/django-google-spanner/django_spanner/operations.py

Lines changed: 2 additions & 0 deletions
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)