Building Queries and Data Views
|
Cast Functions
Cast functions process a source value as the argument and type cast the output to a different datatype. Type casting will typically fail if applied to more than one element. An empty list is allowed, but the result of the type casting will consist of an empty list. Type casting functions are more likely to generate exceptions at run time if the parameter cannot be converted to the corresponding type.
The following table describes Liquid Data data types that conform to the XQuery specification that you can use in type casting functions. For more information about data types, see the XQuery 1.0 and XPath 2.0 Functions and Operators specification. The following cast functions are available:
cast as xs:boolean
Converts the input to a boolean value (true or false).
If the input parameter is empty, the function returns an empty list. Otherwise, Liquid Data generates an error.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:boolean
Notes
This function uses the xf:boolean-from-string function.
XQuery Specification Compliance
Conforms to the current specification; however, Liquid Data does not accept the values "1" and "0" to represent true and false, as described in the W3C XML Schem document.
Examples
- Cast as xs:boolean ("true") returns the boolean value true.
- Cast as xs:boolean ("FalSE") returns the boolean value false.
- Cast as xs:boolean (0) generates a runtime error because the value cannot be cast to a boolean value.
- Cast as xs:boolean (1) generates a runtime error because the value cannot be cast to a boolean value.
- Cast as xs:boolean (()) returns an empty list ().
cast as xs:byte
Converts the input to a byte value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:byte
Notes
This function uses the xf:byte function.
This function will complete sucessfully only if the value cast is a numeric value greater than -128 or less than 128; all other values will fail.
XQuery Specification Compliance
Conforms to the current specification.
Examples
- cast as xs:byte(22) returns the byte value of 22.
- cast as xs:byte(22.9334) returns the byte value 22.
cast as xs:date
Converts the input to a date value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:date
Notes
This function uses the xf:date function.
The string must contain a date in one of these formats:
- YYY-MM-DD
- YYYY-MM-DDZ
- YYYY-MM-DD-hh:mm
where YYYY represents the year, MM represents the month (as a number), DD represents the day, hh and mm represents the number of hours and minutes that the timezone differs from GMT (UTC). Z indicates that the date is in the GMT timezone.
If the string cannot be parsed into a date value, Liquid Data generates an error.
XQuery Specification Compliance
Conforms to the current specification.
Examples
- Cast as xs:date ("2002-07-23") returns the date July 23rd, 2002.
- Cast as xs:date ("2002-07") generates a runtime error because the value cannot be converted to a date.
cast as xs:dateTime
Converts the input to a dateTime value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:dateTime
Notes
This function uses the xf:date function.
XQuery Specification Compliance
Conforms to the current specification.
Examples
- Cast as xs:dateTime ("2002-07-23T23:04:44") returns the dateTime value July 23rd, 2002 at 11:04:44 PM in the local timezone.
- Cast as xs:dateTime ("2002-07-23T23:04:44-08:00") returns the dateTime value July 23rd, 2002 at 11:04:44 PM in the a timezone that is offset by -8 hours from GMT (UTC).
- Cast as xs:date ("2002-07-23") generates a runtime error because no time value is specified.
cast as xs:decimal
Converts the input to a decimal value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:decimal
Notes
This function uses the xf:decimal function.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
- Liquid Data supports "e" and "E" to construct floating point integer values.
Examples
- Cast as xs:decimal ("213") returns the decimal value 213.
- Cast as xs:decimal ("-100") returns the decimal value -100.
- Cast as xs:decimal (0) returns the decimal value 0.
cast as xs:double
Converts the input to a double precision value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:double
Notes
This function uses the xf:double function.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- Cast as xs:double ("21") returns the double precision value 21.0.
- Cast as xs:double ("-3e3") returns the double precision value -3000.0.
- Cast as xs:double (0) returns the double precision value 0.0.
- Cast as xs:double ("abc) generates a runtime error because the string cannot be converted to a double precision value.
cast as xs:float
Converts the input to a floating point value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:float
Notes
This function uses the xf:float function.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- Cast as xs:float ("21") returns the floating point value 21.0.
- Cast as xs:float ("-3e3") returns the floating point value -3000.0.
- Cast as xs:float (0) returns the floating point value 0.0.
- Cast as xs:float ("abc) generates a runtime error because the string cannot be converted to a floating point value.
cast as xs:int
Converts the input to an int value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:int
Notes
This function uses the xf:int function.
XQuery Specification Compliance
Conforms to the current specification.
cast as xs:integer
Converts the input to an integer value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:integer
Notes
This function uses the xf:integer function.
XQuery Specification Compliance
Conforms to the current specification.
cast as xs:long
Converts the input to a long value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:long
Notes
This function uses the xf:long function.
XQuery Specification Compliance
Conforms to the current specification.
cast as xs:short
Converts the input to a short value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:short
Notes
This function uses the xf:short function.
XQuery Specification Compliance
Conforms to the current specification.
cast as xs:string
Converts the input to a string value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:string
Notes
This function uses the xf:string function.
XQuery Specification Compliance
- Liquid Data treats xf:string as both a constructor and an accessor.
- Liquid Data supports only the string format that requires one node of any type as the input.
- Liquid Data accepts xsext:anyType input instead of a list of items.
- Liquid Data returns an optional string.
- Liquid Data does not recognize entities.
Examples
- Cast as xs:string ("abc") returns the string value "abc."
- Cast as xs:string (21) returns the string value "21."
- Cast as xs:string (xf:true()) returns the string value "true."
- Cast as xs:string (xf:false()) returns the string value "false."
cast as xs:time
Converts the input to a time value.
Data Types
- Input data type: xs:anyValue
- Returned data type: xs:time
Notes
This function uses the xf:time function.
XQuery Specification Compliance
Conforms to the current specification.
Examples
- Cast as xs:time ("09:35:20") returns the time value 9:35:20 AM in the current timezone.
- Cast as xs:time (<a>09:35:20</a>) returns the time value 9:35:20 AM in the current timezone.
- Cast as xs:time ("9:35:20") generates a runtime error because the time format is incorrect (hour specified with 1 digit instead of 2) and therefore the string cannot be converted to a time value.
- Cast as xs:time ("21:35:20-08:00") returns the time value 9:35:20 PM in the a timezone that is offset by -8 hours from GMT (UTC).