You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the source dialect is DuckDB and a / is followed by another /, the parser now treats the pair as one operator and builds an IntDiv node.
DuckDB -> DuckDB SELECT 7 // 2 AS v
DuckDB -> PostgreSQL SELECT DIV(7, 2) AS v -- same output MySQL's 7 DIV 2 gets today
Nothing else is affected. a / / b isn't valid SQL in any dialect, so there's no existing input this could change the meaning of. The check is also limited to DuckDB as the source.
Tests
tests/duckdb_integer_division.rs covers the round trip, the lowering to other targets, precedence against +, and that a plain / still parses as ordinary division.
Verdict: request changes before merging revision 56fb9c0d.
This addresses a real DuckDB parsing gap. Validation passed for all four new tests, 1,301 library tests, 208 dialect-matrix tests, and formatting. Additional execution probes identified the following concerns.
Preserve DuckDB’s division semantics when converting to other dialects.
DuckDB’s // behavior depends on operand types. These conversions currently change behavior or produce unsupported SQL:
DuckDB input
Source result
Generated target SQL
Problem
7.0 // 2
3.5
PostgreSQL: DIV(7.0, 2)
Returns 3
7 // 0
NULL
BigQuery: DIV(7, 0)
Raises a division-by-zero error
7 // 2
3
SQLite: DIV(7, 2)
Fails because SQLite has no built-in DIV function
These are existing IntDiv generation limitations exposed by the newly supported DuckDB syntax. Conversions should preserve the source behavior or produce an explicit unsupported diagnostic when that cannot be established.
SQLGlot 30.14.0 reproduces the fractional and zero-division conversion problems, so matching its output is insufficient to establish correctness here.
Use the existing tokenizer support for //.
TokenizerConfig::double_slash_int_div, already used by Vertica, recognizes contiguous // as TokenType::Div. Both multiplication parser paths already support that token.
The proposed parser lookahead also accepts separated slashes:
SELECT7//2;
SELECT7//* comment *//2;
DuckDB rejects both statements, but this revision accepts them even under strict validation and regenerates them as integer division.
Please enable the existing tokenizer setting for DuckDB and remove the two new parser branches. This fits the shared architecture, avoids duplicated logic, and matches SQLGlot’s tokenizer-level recognition.
It also avoids materializing and discarding the second slash token. An allocation probe measured 1,000 additional allocations for 1,000 division expressions with the proposed parser approach compared with the existing tokenizer path. This measures allocation overhead; no latency regression has been established.
Include regression coverage in the routinely executed test suites.
The new standalone duckdb_integer_division test target is not selected by make test-rust-verify or its CI wrappers. Please move these cases into appropriate existing suites so the normal verification process exercises them.
Additional coverage should include fractional operands, explicitly typed floating-point operands, zero divisors, separated slashes, and AST precedence. For precedence, 2 + 7 // 2 distinguishes the possible groupings; the current 1 + 7 // 2 example produces the same result under either grouping. An AST assertion should verify that integer division binds more tightly than addition.
After these changes, please run make test-rust-verify to check for regressions.
This branch has not been deployed
No deployments
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
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.
DuckDB has an integer division operator written as
//. Right now, the parser doesn't recognize it. See DuckDB operator list here: https://duckdb.org/docs/lts/sql/functions/numericWhat this does
When the source dialect is DuckDB and a
/is followed by another/, the parser now treats the pair as one operator and builds anIntDivnode.Nothing else is affected.
a / / bisn't valid SQL in any dialect, so there's no existing input this could change the meaning of. The check is also limited to DuckDB as the source.Tests
tests/duckdb_integer_division.rscovers the round trip, the lowering to other targets, precedence against+, and that a plain/still parses as ordinary division.