Cast expressions

Figure 66. CastExpr

CastExpr

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

Example 159. Cast as expression

"1" cast as integer
      

Result (run with Zorba): 1


Example 160. 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 161. Cast as expression

"2013-04-02" cast as date
      

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


Example 162. 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 163. 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 164. Cast as expression

() cast as date?
      

Result (run with Zorba): 


Example 165. Cast as expression

"2013-04-02" cast as date?
      

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