Product SiteDocumentation Site

11.4. Cast Expressions

A cast expression casts a (single) JSONiq value to a given atomic type. The resulting value is annotated with this type.
Also here, the question mark allows for an empty sequence. An error is raised if the cast is unsuccessful.
Example 11.5. Cast as expression.
"1" cast as integer,
"2013-04-02" cast as date,
() cast as date?,
"2013-04-02" cast as date?
Results:
1
"2013-04-02"
"2013-04-02"

Example 11.6. Cast as expression (failing).
("2013-04-02", "2013-04-03") cast as date,
"foo" cast as integer,
() cast as date
Error:
sequence of more than one item can not be cast to type with
 quantifier '1' or '?'