From bd8feb45b2ee27961b8ead47525db14cf0b87d7d Mon Sep 17 00:00:00 2001 From: Pavel Antoshin Date: Fri, 15 Aug 2025 15:29:54 +0200 Subject: [PATCH 1/2] Add CAST to DECIMAL with parameters to OQL docs --- .../domain-model/oql/oql-expression-syntax.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md index a6cd859b0e6..8cc3ad88f3c 100644 --- a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md +++ b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md @@ -738,6 +738,16 @@ The table below describes which `CAST` conversions are supported: Converting `DATETIME` or `BOOLEAN` to `STRING` returns different format per database. +##### `DECIMAL` precision + +`DECIMAL` data type can have precision and scale as parameters: + +- `DECIMAL(, )` — in the case when both parameters are specified, those values are used as precision and scale of the resulting data type +- `DECIMAL()` — when only precision is specified, scaale is set to 0. The resulting data type in that case is `DECIMAL(, 0)` +- `DECIMAL` — when no parameters are specified, default values are used. Precision is set to 28, and scale is set to 8: `DECIMAL(28, 8)` + +If the original value has more digits in the fractional part than required scale, the fractional part is rounded to the required scale. In that case, rounding is done according to the database configuration. + #### Examples A frequent use case for `CAST` is to convert your date from the `DATETIME` data type to a text formatted `STRING` type: @@ -758,6 +768,21 @@ SELECT (Number : 2) as Normal, (Cast(Number AS DECIMAL) : 2) as Casted FROM Sale | 1 | 1.0 | | 1 | 1.5 | +In case of conversion to `DECIMAL`, scale and precision can be specified + +```sql +SELECT + CAST('123.0987654321' AS DECIMAL) AS default_decimal, + CAST('123.0987654321' AS DECIMAL(20)) AS decimal_precision, + CAST('123.0987654321' AS DECIMAL(20, 6)) AS decimal_precision_scale +FROM Sales.Order +LIMIT 1 +``` + +| default_decimal | decimal_precision | decimal_precision_scale | +|------:|-------:|-------:| +| 123.09876543 | 123 | 123.098765 | + ### COALESCE {#coalesce-expression} Returns the value of the first `expression` that is not NULL. Can be used with columns. From e5813649757459aa698b22ea7ddcbb3339c3df25 Mon Sep 17 00:00:00 2001 From: Mark van Ments Date: Tue, 26 Aug 2025 10:56:27 +0200 Subject: [PATCH 2/2] Proofread --- .../domain-model/oql/oql-expression-syntax.md | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md index 8cc3ad88f3c..26e5a20b732 100644 --- a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md +++ b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md @@ -725,9 +725,9 @@ The table below describes which `CAST` conversions are supported: | From \ To | BOOLEAN | DATETIME | DECIMAL | INTEGER | LONG | STRING (unlimited) | STRING (limited) | |------| :------: | :------: | :------: | :------: | :------: | :------: | :------: | -| BOOLEAN | ✔ | ✘ | ✘ | ✘ | ✘ | ✔* | ✔*¹ | -| DATETIME | ✘ | ✔ | ✘ | ✘ | ✘ | ✔* | ✔*² | -| DECIMAL | ✘ | ✘ | ✔* | ✔* | ✔* | ✔* | ✔*² | +| BOOLEAN | ✔ | ✘ | ✘ | ✘ | ✘ | ✔*³ | ✔*¹ ³ | +| DATETIME | ✘ | ✔ | ✘ | ✘ | ✘ | ✔*³ | ✔*² ³ | +| DECIMAL⁴ | ✘ | ✘ | ✔* | ✔* | ✔* | ✔* | ✔*² | | INTEGER | ✘ | ✘ | ✔ | ✔ | ✔ | ✔ | ✔ | | LONG | ✘ | ✘ | ✔ | ✔ | ✔ | ✔ | ✔ | | STRING | ✘ | ✘ | ✔ | ✔ | ✔ | ✔ | ✔ | @@ -736,15 +736,17 @@ The table below describes which `CAST` conversions are supported: ²The conversion of DATETIME and DECIMAL to STRING (limited) is supported only if the value fully fits into the string length. The conversion can fail if the resulting string length is less than 20. -Converting `DATETIME` or `BOOLEAN` to `STRING` returns different format per database. +³Converting `DATETIME` or `BOOLEAN` to `STRING` returns different format per database. -##### `DECIMAL` precision +⁴See [`DECIMAL` precision](#dec-prec), below, for further information. -`DECIMAL` data type can have precision and scale as parameters: +##### `DECIMAL` precision{#dec-prec} -- `DECIMAL(, )` — in the case when both parameters are specified, those values are used as precision and scale of the resulting data type -- `DECIMAL()` — when only precision is specified, scaale is set to 0. The resulting data type in that case is `DECIMAL(, 0)` -- `DECIMAL` — when no parameters are specified, default values are used. Precision is set to 28, and scale is set to 8: `DECIMAL(28, 8)` +`DECIMAL` data type can have precision and scale as parameters. This will have the following impact on the way data is converted: + +* `DECIMAL(, )` – when both parameters are specified, those values are used as precision and scale of the resulting data type +* `DECIMAL()` – when only precision is specified, scale is set to 0. The resulting data type in that case is `DECIMAL(, 0)` +* `DECIMAL` – when no parameters are specified, default values are used. Precision is set to 28, and scale is set to 8: `DECIMAL(28, 8)` If the original value has more digits in the fractional part than required scale, the fractional part is rounded to the required scale. In that case, rounding is done according to the database configuration. @@ -768,7 +770,7 @@ SELECT (Number : 2) as Normal, (Cast(Number AS DECIMAL) : 2) as Casted FROM Sale | 1 | 1.0 | | 1 | 1.5 | -In case of conversion to `DECIMAL`, scale and precision can be specified +In the case of conversion to `DECIMAL`, scale and precision can be specified ```sql SELECT