Unsupported query: power() database function doesn't accept negative exponents
timgraham opened this issue · 4 comments
timgraham commented
======================================================================
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 commented
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 commented
Do you see the behavior changing in the future or should the test be marked an expected failure?
yuzefovich commented
I feel like we won't address this in the near future, so I would mark the failure as expected. cc @jordanlewis
jordanlewis commented
Agreed.