Type promotion
Type promotion is a process that converts an atomic value from its original type to the type that is expected by an expression. XQuery uses type promotion during the evaluation of function calls and operators that accept numeric or string operands.
XQuery permits
the
following type promotions:
- Numeric type promotion:
- A value of type xs:decimal (or any type that is derived by restriction
from xs:decimal) can be promoted to xs:double. The result of this
promotion
is created by casting the original value to the required type.In the following example, a sequence that contains the xs:double value 13.54e-2 and the xs:decimal value 100 is passed to the fn:sum function, which returns a value of type xs:double:
fn:sum(xs:double(13.54e-2), xs:decimal(100))
Type promotion and subtype substitution differ
in the following ways:
- For type promotion, the atomic value is actually converted from its original type to the type that is expected by an expression.
- For subtype substitution, an expression that expects a specific type can be invoked with a value that is derived from that type. However, the value retains its original type.