diff --git a/web/book/src/reference/syntax/operators.md b/web/book/src/reference/syntax/operators.md index 5e9b95a04f7e..4000bc18d048 100644 --- a/web/book/src/reference/syntax/operators.md +++ b/web/book/src/reference/syntax/operators.md @@ -34,6 +34,25 @@ operations and for function calls (see the discussion below.) | or | \|\| | 9 | left-to-right | | function call | | 10 | | +## Division and integer division + +The `/` operator performs division that always returns a float value, while the +`//` operator does integer division (truncated division) that always returns an +integer value. + +```prql +prql target:sql.sqlite + +from [ + {a = 5, b = 2}, + {a = 5, b = -2}, +] +select { + div_out = a / b, + int_div_out = a // b, +} +``` + ## Coalesce We can coalesce values with an `??` operator. Coalescing takes either the first diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__operators__division-and-integer-division__0.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__operators__division-and-integer-division__0.snap new file mode 100644 index 000000000000..c1e649d9be10 --- /dev/null +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__operators__division-and-integer-division__0.snap @@ -0,0 +1,20 @@ +--- +source: web/book/tests/documentation/book.rs +expression: "prql target:sql.sqlite\n\nfrom [\n {a = 5, b = 2},\n {a = 5, b = -2},\n]\nselect {\n div_out = a / b,\n int_div_out = a // b,\n}\n" +--- +WITH table_0 AS ( + SELECT + 5 AS a, + 2 AS b + UNION + ALL + SELECT + 5 AS a, + -2 AS b +) +SELECT + (a * 1.0 / b) AS div_out, + ROUND(ABS(a / b) - 0.5) * SIGN(a) * SIGN(b) AS int_div_out +FROM + table_0 +