Skip to content
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

Unsupported query: power() database function doesn't accept negative exponents #22

Open
timgraham opened this issue Oct 9, 2019 · 4 comments

Comments

@timgraham
Copy link
Collaborator

======================================================================
ERROR: test_integer (db_functions.math.test_power.PowerTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.NumericValueOutOfRange: power(): integer out of range


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tim/code/django/tests/db_functions/math/test_power.py", line 37, in test_integer
    big_power=Power('big', 'small'),
  File "/home/tim/code/django/django/db/models/query.py", line 653, in first
    for obj in (self if self.ordered else self.order_by('pk'))[:1]:
  File "/home/tim/code/django/django/db/models/query.py", line 274, in __iter__
    self._fetch_all()
  File "/home/tim/code/django/django/db/models/query.py", line 1242, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/tim/code/django/django/db/models/query.py", line 55, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/home/tim/code/django/django/db/models/sql/compiler.py", line 1100, in execute_sql
    cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/tim/code/django/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/tim/code/django/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/tim/code/django/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.DataError: power(): integer out of range

Is it intentional?

Example SQL:

SELECT ... power("db_functions_integermodel"."big", "db_functions_integermodel"."small") AS "big_power"
FROM "db_functions_integermodel"

where big = 3 and small = -1.

@yuzefovich
Copy link
Member

This is a limitation of Cockroach in that for pow(a, b) where both a and b are integers, the result is expected to be integer as well. For pow(3, -1) it is not, so we're returning a misleading integer out of range error.

@timgraham
Copy link
Collaborator Author

Do you see the behavior changing in the future or should the test be marked an expected failure?

@yuzefovich
Copy link
Member

I feel like we won't address this in the near future, so I would mark the failure as expected. cc @jordanlewis

@jordanlewis
Copy link
Member

Agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants