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 53c57234d16..a6cd859b0e6 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 @@ -555,7 +555,7 @@ The `IS` operator can be used to filter out rows with values that are NULL. For The `CASE` expression is a conditional expression, similar to if/else statements in other programming languages. If the result of a following `WHEN` condition is `TRUE`, the value of the `CASE` expression is the result that follows the condition and the remainder of the `CASE` expression is not processed. If the result is not `TRUE`, any subsequent `WHEN` clauses are examined in the same manner. If no `WHEN` condition yields `TRUE`, the value of the `CASE` expression is the result of the `ELSE` clause. If the `ELSE` clause is omitted and no condition is `TRUE`, the result is null. -If [OQL v2](/refguide/oql-v2/) is enabled, additional data type validations apply to result expressions of `CASE`. See the corresponding [page](/refguide/oql-v2/#case-validations) for details. +If [OQL v2](/refguide/oql-v2/) is enabled, additional data type validations apply to results of `CASE` expressions. See [`CASE`](/refguide/oql-v2/#case-validations) in *OQL Version 2 Features* for details. #### Syntax @@ -625,7 +625,7 @@ FROM Sales.Order | Doe | 2 | 5.0 | Regular | | Moose | 3 | 8.2 | Priority | -If result expressions have different numeric types, date type of the result expression in the first WHEN has priority, and the whole CASE expression has type of that result expression. This behavior matches the behavior of supported database vendors. +If expression results have different numeric types, the data type of the expression result is defined based on [type coercion precedence](#type-coercion). ```sql SELECT @@ -643,11 +643,13 @@ SELECT FROM Sales.Order ``` -| LastName | Number | Price | PriceOrNumber (type: Decimal) | NumberOrPrice (type: Integer) | +| LastName | Number | Price | PriceOrNumber (type: Decimal) | NumberOrPrice (type: Decimal¹) | |:---------|-------:|------:|--------------:|--------------:| -| Doe | 7 | 1.5 | 1.5 | 7 | -| Doe | 2 | 5.0 | 5.0 | 2 | -| Moose | 3 | 8.2 | 3.0 | 8 | +| Doe | 7 | 1.5 | 1.5 | 7.0 | +| Doe | 2 | 5.0 | 5.0 | 2.0 | +| Moose | 3 | 8.2 | 3.0 | 8.0 | + +¹In OQL v1, the expression gets the type of the first argument. If you use OQL v1, the type of `NumberOrPrice` in the example above is Integer, not Decimal. ### Operator Precedence @@ -796,7 +798,7 @@ SELECT COALESCE(LastName, FirstName) AS Name FROM Sales.Customer | Doe | | Jane | -If arguments of `COALESCE` have different numeric types, the expression gets the type of the first argument. This behavior matches the behavior of supported database vendors. +If all arguments have different numeric types, the data type of the expression result is defined based on [type coercion precedence](#type-coercion). ```sql SELECT @@ -805,10 +807,12 @@ SELECT FROM Sales.Customer ``` -| AgeOrAmount (type: Integer) | AmountOrAge (type: Decimal) | +| AgeOrAmount (type: Decimal) | AmountOrAge (type: Decimal²) | |------:|------:| -| 25 | 25.0 | -| 42 | 42.3 | +| 25.0 | 25.0 | +| 42.3 | 42.3 | + +²In OQL v1, the expression gets the type of the first argument. If you use OQL v1, the type of `AgeOrAmount` in the example above is Integer, not Decimal. ### DATEDIFF {#datediff-function} diff --git a/content/en/docs/refguide/modeling/domain-model/oql/oql-v2.md b/content/en/docs/refguide/modeling/domain-model/oql/oql-v2.md index cbf0adb95b7..b0097093e44 100644 --- a/content/en/docs/refguide/modeling/domain-model/oql/oql-v2.md +++ b/content/en/docs/refguide/modeling/domain-model/oql/oql-v2.md @@ -44,11 +44,11 @@ OQL v2 has more strict data type validation of some functions and other expressi #### `CASE` {#case-validations} -In OQL v2, all result expressions of a [CASE](/refguide/oql-expression-syntax/#case-expression) expression should have matching types or be Null. In OQL v1, there was no such validation, and handling of different types was delegated to the database, which made the behavior database-specific and unreliable. +In OQL v2, all results of a [CASE](/refguide/oql-expression-syntax/#case-expression) expression should have matching types or be Null. In OQL v1, there was no such validation, and handling of different types was delegated to the database, which made the behavior database-specific and unreliable. -Also, in OQL v2 it is no longer possible to have Null as the result of all result expressions of CASE. In OQL v1, that was allowed, but would lead to database-level exceptions for some database vendors. +Also, in OQL v2 it is no longer possible to have Null as the only result a CASE expression. In OQL v1, that was allowed, but would lead to database-level exceptions for some database vendors. -Numeric types Integer, Long and Decimal are considered matching. See [examples](/refguide/oql-expression-syntax/#case-expression-examples) of `CASE` expressions for details on how different numeric types are combined. +Identical values of numeric types Integer, Long, and Decimal are considered matching. The type of the resulting expression is defined according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion). In OQL v1, the type of the expression was defined based on the result of the first expression of `CASE`. #### `COALESCE` {#coalesce-validations} @@ -58,7 +58,7 @@ In OQL v2, all arguments of a [COALESCE](/refguide/oql-expression-syntax/#coales Also, in OQL v2 it is no longer possible to have a COALESCE expression where all arguments are Null literals. In OQL v1, that was allowed, but would lead to database-level exceptions for some database vendors. -Numeric types Integer, Long and Decimal are considered matching. See [examples](/refguide/oql-expression-syntax/#coalesce-expression-examples) of `COALESCE` for details on how different numeric types are combined. +Identical values of numeric types Integer, Long, and Decimal are considered matching. The type of the resulting expression is defined according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion). In OQL v1, the type of the expression was defined based on the result of the first expression of `COALESCE`. #### `LENGTH` {#length-validations} @@ -229,15 +229,11 @@ SELECT Attribute1 + Attribute2 AS SumAttr FROM Module.Entity ``` -In OQL v1, the result of the arithmetic operation will always be of type pf the first attribute in the expression because it is handled by the database. Therefore, the result would depend on the underlying database engine. +In OQL v1, the type of the result of the arithmetic operation will always be the type of the first attribute in the expression. Therefore, the result would depend on the underlying database engine. -When handling numeric types in OQL v2 (Integer, Long, and Decimal), the result of the operation is always the most precise attribute type, using the following precedence: +When handling numeric types in OQL v2 (Integer, Long, and Decimal), the result type is defined according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion). -* Decimal (highest) -* Long -* Integer - -If any side of the operation is of a non-numeric type, no casting is performed, and the result is handled by the database, as in OQL v1. See [Expression syntax](/refguide/oql-expression-syntax/#type-coercion) for more information. +No casting is performed if the type of either side of the operation is non-numeric, and the result is handled by the database, as in OQL v1. ### The Result Type of `ROUND` Is Now `Decimal`