Skip to content

django: fix power operator #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions django_spanner/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
# https://github.com/orijtech/django-spanner/issues/331
'expressions.tests.ExpressionOperatorTests.test_lefthand_division',
'expressions.tests.ExpressionOperatorTests.test_right_hand_division',
# power operator doesn't work:
# https://github.com/orijtech/django-spanner/issues/333
# power operator produces a float result, which can't be assigned to
# an integer column:
# https://github.com/orijtech/django-spanner/issues/331
'expressions.tests.ExpressionOperatorTests.test_lefthand_power',
'expressions.tests.ExpressionOperatorTests.test_righthand_power',
# Cloud Spanner's docs: "The rows that are returned by LIMIT and OFFSET
Expand Down
2 changes: 2 additions & 0 deletions django_spanner/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def format_for_duration_arithmetic(self, sql):
def combine_expression(self, connector, sub_expressions):
if connector == '%%':
return 'MOD(%s)' % ', '.join(sub_expressions)
elif connector == '^':
return 'POWER(%s)' % ', '.join(sub_expressions)
return super().combine_expression(connector, sub_expressions)

def combine_duration_expression(self, connector, sub_expressions):
Expand Down