Type system
XQuery is a strongly-typed language in which the operands of various expressions, operators, and functions must conform to expected types. The type system for DB2® XQuery includes the built-in types of XML Schema and the predefined types of XQuery.
The built-in types of XML Schema are in the namespace http://www.w3.org/2001/XMLSchema, which has the predeclared namespace prefix xs. Some examples of built-in schema types include xs:integer, xs:string, and xs:date.
The predefined types of XQuery are in the namespace http://www.w3.org/2005/xpath-datatypes, which has the predeclared namespace prefix xdt. Some examples of predefined types of XQuery include xdt:untypedAtomic, xdt:yearMonthDuration, and xdt:dayTimeDuration.
Each data type has a lexical form, which is a string that can be cast into the given type or that can be used to represent a value of the given type after serialization.
- The type hierarchy
The DB2 XQuery type hierarchy shows all of the types that can be used in XQuery expressions. - Types by category
DB2 XQuery has the following categories of types: generic, untyped, string, numeric, date, time, duration, and other. - Constructor functions for built-in data types
Constructor functions convert an instance of one atomic type into an instance of a different atomic type. An implicitly-defined constructor function exists for each of the built-in atomic types that are defined in XML Schema. - Type casting
Type conversions are supported between xdt:untypedAtomic, xs:integer, the two derived types of xs:duration (xdt:yearMonthDuration and xdt:dayTimeDuration), and the nineteen primitive types that are defined in XML Schema. Type conversions are used in cast expressions and type constructors. - anyAtomicType data type
The xdt:anyAtomicType data type denotes a context where any atomic type can be used. This data type serves as the base type for all atomic types. An instance of an atomic type is a single nondecomposable value such as an integer, a string, or a date. Derived from the xs:anySimpleType data type. - anySimpleType data type
The xs:anySimpleType data type denotes a context where any simple type can be used. This data type serves as the base type for all simple types. An instance of a simple type can be any sequence of atomic values. Derived from the xs:anyType data type. - anyType data type
The xs:anyType data type encompasses any sequence of zero or more nodes and zero or more atomic values. - anyURI data type
The xs:anyURI data type represents a Uniform Resource Identifier (URI). Derived from data type xdt:anyAtomicType. - base64Binary data type
The xs:base64Binary data type represents base64-encoded binary data. Derived from data type xdt:anyAtomicType. - boolean data type
The xs:boolean data type supports the mathematical concept of binary-valued logic: true or false. Derived from data type xdt:anyAtomicType. - byte data type
The xs:byte data type represents an integer that is less than or equal to 127 and greater than or equal to -128. Derived from the xs:short data type. - date data type
The xs:date data type represents an interval of exactly one day in duration that begins on the first moment of a specific day. The xs:date data type consists of year, month, and day properties that are expressed as integer values and an optional time zone indicator. Derived from the xdt:anyAtomicType data type. - dateTime data type
The xs:dateTime data type represents an instant that has the following properties: year, month, day, hour, and minute properties that are expressed as integer values; a second property that is expressed as a decimal value; and an optional time zone indicator. Derived from data type xdt:anyAtomicType. - dayTimeDuration data type
The xdt:dayTimeDuration data type represents a duration of time that is expressed by days, hours, minutes, and seconds components. Derived from the xs:duration data type. - decimal data type
The xs:decimal data type represents a subset of the real numbers that can be represented by decimal numerals. Derived from data type xdt:anyAtomicType. - double data type
The xs:double data type is patterned after the IEEE double-precision 64-bit floating point type. Derived from data type xdt:anyAtomicType. - duration data type
The xs:duration data type represents a duration of time that is expressed by the Gregorian year, month, day, hour, minute, and second components. Derived from data type xdt:anyAtomicType. - ENTITY data type
The xs:ENTITY data type represents the ENTITY attribute type from XML 1.0 (Third Edition). Derived from the xs:NCName data type. - float data type
The xs:float data type is patterned after the IEEE single-precision 32-bit floating point type. Derived from data type xdt:anyAtomicType. - gDay data type
The xs:gDay data type represents a Gregorian day that recurs. Gregorian calendar days are defined in ISO 8601. Derived from data type xdt:anyAtomicType. - gMonth data type
The xs:gMonth data type represents a Gregorian month that recurs every year. Gregorian calendar months are defined in ISO 8601. Derived from data type xdt:anyAtomicType. - gMonthDay data type
The xs:gMonthDay data type represents a Gregorian date that recurs. Gregorian calendar dates are defined in ISO 8601. Derived from data type xdt:anyAtomicType. - gYear data type
The xs:gYear data type represents a Gregorian calendar year. Gregorian calendar years are defined in ISO 8601. Derived from data type xdt:anyAtomicType. - gYearMonth data type
The xs:gYearMonth data type represents a specific Gregorian month in a specific Gregorian year. Gregorian calendar months are defined in ISO 8601. Derived from data type xdt:anyAtomicType. - hexBinary data type
The xs:hexBinary data type represents hex-encoded binary data. Derived from data type xdt:anyAtomicType. - ID data type
The xs:ID data type represents the ID attribute type from XML 1.0 (Third Edition). Derived from xs:NCName data type. - IDREF data type
The xs:IDREF data type represents the IDREF attribute type from XML 1.0 (Third Edition). Derived from the xs:NCName data type. - int data type
The xs:int data type represents an integer that is less than or equal to 2 147 483 647 and greater than or equal to -2 147 483 648. Derived from the xs:long data type. - integer data type
The xs:integer data type represents a number that is less than or equal to 9 223 372 036 854 775 807 and greater than or equal to -9 223 372 036 854 775 808. Derived from xs:decimal data type. - language data type
The xs:language data type represents a natural language identifier as defined by RFC 3066. Derived from data type xs:token. - long data type
The xs:long data type represents an integer that is less than or equal to 9 223 372 036 854 775 807 and greater than or equal to -9 223 372 036 854 775 808. Derived from data type xs:integer. - Name data type
The xs:Name data type represents an XML Name. Derived from the xs:token data type. - NCName data type
The xs:NCName data type represents an XML noncolonized name. Derived from the xs:Name data type. - negativeInteger data type
The xs:negativeInteger data type represents an integer that is less than zero. Derived from data type xs:nonPositiveInteger. - NMTOKEN data type
The xs:NMTOKEN data type represents the NMTOKEN attribute type from XML 1.0 (Third Edition). Derived from the xs:token data type. - nonNegativeInteger data type
The xs:nonNegativeInteger data type represents an integer that is greater than or equal to zero. Derived from the xs:integer data type. - nonPositiveInteger data type
The xs:nonPositiveInteger data type represents an integer that is less than or equal to zero. Derived from the xs:integer data type. - normalizedString data type
The xs:normalizedString data type represents a white space-normalized string. Derived from data type xs:string. - NOTATION data type
The xs:NOTATION data type represents the NOTATION attribute type from XML 1.0 (Third Edition). Derived from data type xdt:anyAtomicType. - positiveInteger data type
The xs:positiveInteger data type represents a positive integer that is greater than or equal to 1. Derived from the xs:nonNegativeInteger data type. - QName data type
The xs:QName data type represents an XML qualified name (QName). A QName includes an optional namespace prefix, a URI that identifies the XML namespace, and a local part, which is an NCName. Derived from data type xdt:anyAtomicType. - short data type
The xs:short data type represents an integer that is less than or equal to 32 767 and greater than or equal to -32 768. Derived from the xs:int data type. - string data type
The xs:string data type represents a character string. Derived from data type xdt:anyAtomicType. - time data type
The xs:time data type represents an instant of time that recurs every day. Derived from data type xdt:anyAtomicType. - token data type
The xs:token data type represents a tokenized string. Derived from the xs:normalizedString data type. - unsignedByte data type
The xs:unsignedByte data type represents an unsigned integer that is less than or equal to 255. Derived from xs:unsignedShort data type. - unsignedInt data type
The xs:unsignedInt data type represents an unsigned integer that is less than or equal to 4 294 967 295. Derived from xs:unsignedLong data type. - unsignedLong data type
The xs:unsignedLong data type represents an unsigned integer that is less than or equal to 9 223 372 036 854 775 807. Derived from the xs:nonNegativeInteger data type. - unsignedShort data type
The xs:unsignedShort data type represents an unsigned integer that is less than or equal to 65 535. Derived from the xs:unsignedInt data type. - untyped data type
The xdt:untyped data type denotes a node that has not been validated by an XML schema. Derived from data type xs:anyType. - untypedAtomic data type
The xdt:untypedAtomic data type denotes an atomic value that has not been validated by an XML schema. Derived from data type xdt:anyAtomicType. - yearMonthDuration data type
The xdt:yearMonthDuration data type represents a duration of time that is expressed by the Gregorian year and month components. Derived from the xs:duration data type.