[BREAKING] Use Python-style division operator (/ is always floating point division, // is integer division) #7082
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.
This PR reworks the division operator in DuckDB to mimic that of Python, where
/is always a floating point division (even if the arguments are integers), and the current division operator is moved to//. This results in generally more intuitive results. Particularly for data science workflows integer division is rarely needed - and can often produce subtly wrong and confusing results, especially for beginners who might not be familiar with what integer division is or why integer division works in this manner.Most analytical systems seem to deviate towards this standard, with mostly older systems preferring integer division.
Integer Division: SQLite, Postgres, SQL Server
Floating Point Division: MySQL, SparkSQL, BigQuery, Snowflake, ClickHouse
In addition, other popular systems in the analytics space take this approach, such as Python itself, Pandas, NumPy, Polars, R and dplyr.
In order to faciliate a more smooth transition, we also add the
integer_divisionflag that allows users to revert back to the old behavior, e.g.: