Fix floordiv (//) for float/numeric by int with div_is_floordiv dialects#13191
Open
r266-tech wants to merge 1 commit intosqlalchemy:mainfrom
Open
Fix floordiv (//) for float/numeric by int with div_is_floordiv dialects#13191r266-tech wants to merge 1 commit intosqlalchemy:mainfrom
r266-tech wants to merge 1 commit intosqlalchemy:mainfrom
Conversation
…loordiv dialects When a dialect has div_is_floordiv=True (e.g. PostgreSQL), integer division already truncates. However, the visit_floordiv_binary method was skipping the FLOOR() wrapper whenever the *right* operand was Integer, even if the *left* operand was Float or Numeric. This caused incorrect SQL like float_col / int_col instead of FLOOR(float_col / int_col). Fix: only skip FLOOR() when *both* operands are Integer. Fixes: sqlalchemy#10528
sqla-tester
reviewed
Mar 23, 2026
Collaborator
sqla-tester
left a comment
There was a problem hiding this comment.
OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision c9cbc47 of this pull request into gerrit so we can run tests and reviews and stuff
Collaborator
|
New Gerrit review created for change c9cbc47: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6629 |
Member
|
Looks ok to me |
Member
|
hi - some existing tests need to be adjusted for the new syntax, can you update? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a dialect has
div_is_floordiv=True(e.g. PostgreSQL), integer/already truncates toward zero. However,visit_floordiv_binarywas skipping theFLOOR()wrapper whenever the right operand wasInteger, even if the left operand wasFloatorNumeric. This produced incorrect SQL likefoo.float_col / foo.int_colinstead ofFLOOR(foo.float_col / foo.int_col).Fix: only skip
FLOOR()when both operands areInteger.Before (PostgreSQL dialect):
After:
Fixes: #10528
cc @zzzeek