Open timgraham opened 4 years ago
I think the problem is that the division operator yields float (or at least something besides int) and then the float can't be assigned to an integer column (similar to #20). @rafiss do you think this merits an issue in https://github.com/cockroachdb/cockroach. Possibly it would be covered by https://github.com/cockroachdb/cockroach/issues/38965?
These queries do work.
> SELECT 4 / 2;
?column?
------------
2
SELECT ..., ("expressions_number"."the_integer" / 2) AS "i" FROM "expressions_number"
I don't think this could be addressed by automatically typecasting, since I don't think we'd add logic that could make the result lose precision without the user intending it. So I think the real DB issue we'd need to fix is: https://github.com/cockroachdb/cockroach/issues/41448
If we know we're working with integers would one option be to use this operator instead, as outlined in the issue comment below?
One note: the // operator can be used if integer division is required.
https://github.com/cockroachdb/cockroach/issues/41448#issuecomment-940126328
Operators are customized in DatabaseOperations.combine_expression()
, but it isn't possible to determine the types (e.g. integer) of the column names or placeholders in sub_expressions
.
These queries work with psycopg3.
Correction: these queries only work with server-side cursors. With client-side-binding cursors (which Django defaults to), this issue remains the same.
Dividing an integer column by another integer in an
UPDATE
query crashes:Is there a plan to add support?
SQL: