Cast expressions

Figure 56. CastExpr

CastExpr

A cast expression casts a JSONiq value to a given atomic type. The resulting value is annotated with this type.

Example 152. Cast as expression

"1" cast as integer
      

Result (run with Zorba): 1


Example 153. 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 154. Cast as expression

"2013-04-02" cast as date
      

Result (run with Zorba): 2013-04-02


Example 155. 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 156. 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 157. Cast as expression

() cast as date?
      

Result (run with Zorba): 


Example 158. Cast as expression

"2013-04-02" cast as date?
      

Result (run with Zorba): 2013-04-02