DB2 10.5 for Linux, UNIX, and Windows

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.

The type conversions that are supported are indicated in the following tables. Each table shows the primitive types that are the source of the type conversion on the left side and the primitive types that are the target of the type conversion on the top. The first table contains the targets from xdt:untypedAtomic to xs:dateTime, and the second table contains the targets from xs:time to xs:NOTATION.

The cells in the tables contain one of three characters:
Y
Yes. Indicates that a conversion from values of the source type to the target type is supported.
N
No. Indicates that a conversion from values of the source type to the target type is not supported.
M
Maybe. Indicates that a conversion from values of the source type to the target type might succeed for some values and fail for other values.

Casting is not supported to or from xs:anySimpleType or to or from xdt:anyAtomicType.

If an unsupported casting is attempted, an error is returned.

Table 1. Primitive type casting, part 1 (targets from xdt:untypedAtomic to xs:dateTime)
Source data type Target uA Target string Target float Target double Target decimal Target integer Target dur Target yMD Target dTD Target dT
uA Y Y M M M M M M M M
string Y Y M M M M M M M M
float Y Y Y Y M M N N N N
double Y Y M Y M M N N N N
decimal Y Y Y Y Y M N N N N
integer Y Y Y Y Y Y N N N N
dur Y Y N N N N Y Y Y N
yMD Y Y N N N N Y Y N N
dTD Y Y N N N N Y N Y N
dT Y Y N N N N N N N Y
time Y Y N N N N N N N N
date Y Y N N N N N N N Y
gYM Y Y N N N N N N N N
gYr Y Y N N N N N N N N
gMD Y Y N N N N N N N N
gDay Y Y N N N N N N N N
gMon Y Y N N N N N N N N
bool Y Y Y Y Y Y N N N N
b64 Y Y N N N N N N N N
hxB Y Y N N N N N N N N
aURI Y Y N N N N N N N N
QN Y Y N N N N N N N N
NOT Y Y N N N N N N N N
Table 2. Primitive type casting, part 2 (targets from xs:time to xs:NOTATION)
Source data type Target time Target date Target gYM Target gYr Target gMD Target gDay Target gMon Target bool Target b64 Target hxB Target aURI Target QN Target NOT
uA M M M M M M M M M M M N N
string M M M M M M M M M M M M M
float N N N N N N N Y N N N N N
double N N N N N N N Y N N N N N
decimal N N N N N N N Y N N N N N
integer N N N N N N N Y N N N N N
dur N N N N N N N N N N N N N
yMD N N N N N N N N N N N N N
dTD N N N N N N N N N N N N N
dT Y Y Y Y Y Y Y N N N N N N
time Y N N N N N N N N N N N N
date N Y Y Y Y Y Y N N N N N N
gYM N N Y N N N N N N N N N N
gYr N N N Y N N N N N N N N N
gMD N N N N Y N N N N N N N N
gDay N N N N N Y N N N N N N N
gMon N N N N N N Y N N N N N N
bool N N N N N N N Y N N N N N
b64 N N N N N N N N Y Y N N N
hxB N N N N N N N N Y Y N N N
aURI N N N N N N N N N N Y N N
QN N N N N N N N N N N N N N
NOT N N N N N N N N N N N N M
The columns and rows are identified by short codes that identify the following types:
  • uA = xdt:untypedAtomic
  • string = xs:string
  • float = xs:float
  • double = xs:double
  • decimal = xs:decimal
  • integer = xs:integer
  • dur = xs:duration
  • yMD = xdt:yearMonthDuration
  • dTD = xdt:dayTimeDuration
  • dT = xs:dateTime
  • time = xs:time
  • date = xs:date
  • gYM = xs:gYearMonth
  • gYr = xs:gYear
  • gMD = xs:gMonthDay
  • gDay = xs:gDay
  • gMon = xs:gMonth
  • bool = xs:boolean
  • b64 = xs:base64Binary
  • hxB = xs:hexBinary
  • aURI = xs:anyURI
  • QN = xs:QName
  • NOT = xs:NOTATION