Product SiteDocumentation Site

5.7.4. Cast expressions

CastExpr
Figure 5.50. CastExpr

A cast expression casts a JSONiq value to a given atomic type. The resulting value is annotated with this type.
Example 5.147. Cast as expression
"1" cast as integer
Result (run with Zorba):
1

Example 5.148. Cast as expression
"foo" cast as integer
Result (run with Zorba):
An error was raised: "foo": value of type xs:string is not castable to type xs:integer

Example 5.149. Cast as expression
"2013-04-02" cast as date
Result (run with Zorba):
2013-04-02

Example 5.150. Cast as expression
() cast as date
Result (run with Zorba):
An error was raised: empty sequence can not be cast to type with quantifier '1'

Example 5.151. Cast as expression
("2013-04-02", "2013-04-03") cast as date
Result (run with Zorba):
An error was raised: sequence of more than one item can not be cast to type with quantifier '1' or '?'

The question mark allows for an empty sequence.
Example 5.152. Cast as expression
() cast as date?
Result (run with Zorba):

Example 5.153. Cast as expression
"2013-04-02" cast as date?
Result (run with Zorba):
2013-04-02