APPENDIX B

image

XQuery Data Types

SQL Server 2012 supports the data types defined in the XQuery Data Model (XDM). The supported data types are listed with their definitions in Table B-1. The diagram in Figure B-1 is a quick reference showing the relationships between the XDM data types.

Table B-1. XQuery Data Types

Type Description
Base Types
xs:anySimpleType This is the base type for all simple built-in types.
xs:anyType This is the base type for xs:anySimpleType and complex built-in types.
Date/Time Types
xs:date This type represents a Gregorian calendar–based date value exactly one day in length, represented in the format yyyy-mm-dd[time_offset]. time_offset can be a capital Z for zero-meridian (UTC), or in the format +/−hh:mm to represent a UTC offset. An example of a valid xs:date is 2006-12-25Z, which represents December 25, 2006, UTC time.
xs:dateTime This type represents a Gregorian calendar–based date and time value with precision to 1/1000th of a second. The format is yyyy-mm-ddThh: mm:ss.sss[time_offset]. Time is specified using a 24-hour clock. As with xs:date, time_offset can be a capital Z (UTC) or a UTC offset in the format +/−hh:mm. A valid xs:dateTime value is 2006-10-30T13:00: 59.500-05:00, which represents October 30, 2006, 1:00:59.5 PM, US Eastern Standard time. Unlike SQL Server 2005, in SQL Server 2012 the xs:dateTime type maintains the time zone information you assign instead of automatically converting all date/time values to a single time zone. The time zone is also not mandatory in SQL Server 2012.
xs:duration This type represents a Gregorian calendar–based temporal (time- based) duration, represented as PyyyyYmmMddDThhHmmMss.sssS. P0010Y03M12DT00H00M00.000S, for instance, represents 10 years, 3 months, 12 days.
xs:gDay This type represents a Gregorian calendar–based day. The format is dd[time_offset] (notice the three preceding hyphen [-] characters). The time_offset is optional. A valid xs:gDay value is 09Z, which stands for the ninth day of the month, UTC time.
xs:gMonth This type represents a Gregorian calendar–based month. The format is --mm[time_offset] (notice the two preceding hyphen characters). time_offset is optional. A valid xs:gMonth value is −12, which stands for December.
xs:gMonthDay This type represents a Gregorian calendar–based month and day. The format is --mm-dd[time_offset] (notice the two preceding hyphens). The time_offset for this data type is optional. A valid xs:gMonthDay value is --02-29 for February 29.
xs:gYear This type represents a Gregorian calendar–based year. The format is yyyy[time_offset]. The time_offset is optional. The year can also have a preceding hyphen character indicating a negative (BCE—“before the Christian Era”) year as opposed to a positive (CE—“Christian Era”) date. A valid xs:gYear value is −0044 for 44 BCE. Notice that all four digits are required in the year representation, even for years that can be normally represented with less than four digits.
xs:gYearMonth This type represents a Gregorian calendar–based year and month. The format is yyyy-mm[time_offset]. The time_offset for this data type is optional and can be Z or a UTC offset. A valid xs:gYearMonth value is 200101 for January 2001.
xs:time This type represents a time value with precision to 1/1000th of a second, using a 24-hour clock representation. The format is hh:mm:ss.sss [time_offset]. As with other temporal data types, time_offset can be Z (UTC) or a UTC offset in the format +/−hh:mm. A valid xs:time value is 23:59:59.000-06:00, which represents 11:59:59 PM, US Central Standard time. The canonical representation of midnight in24-hour format is 00:00:00.
Binary Types
xs:base64Binary This type represents Base64-encoded binary data. Base64-encoding symbols are defined in RFC 2045 (www.ietf.org/rfc/rfc2045.txt) as A through Z, a through z, 0 through 9, +, /, and the trailing = sign. Whitespace characters are also allowed, and lowercase letters are considered distinct from uppercase letters. An example of a valid xs:base64Binary value is QVByZXNzIEJvb2tzIEFuZCBTUUwgU2V⃞ ydmVyIDIwMDU = .
xs:hexBinary This type represents hexadecimal-encoded binary data. The symbols defined for encoding data in hexadecimal format are 0 through 9, A through F, and a through f. Upper- and lowercase letters A through F are considered equivalent by this data type. An example of a valid xs:hexBinary value is 6170726573732E636F6D.
Boolean Type
xs:Boolean This type represents a Boolean binary truth value. The values supported are true (1) and false (0). An example of a valid xs:boolean value is true.
Numeric Types
xs:byte This type represents an 8-bit signed integer in the range −128 to +127.
xs:decimal This type represents an exact decimal value up to 38 digits in length. These numbers can have up to 28 digits before the decimal point and up to 10 digits after the decimal point. A valid xs:decimal value is 8372.9381.
xs:double This type represents a double-precision floating point value patterned after the IEEE standard for floating point types. The representation of values is similar to xs:float values nE[+/−]e, where n is the mantissa followed by the letter E or e and an exponent e. The range of valid values for xs:double are approximately −1.79E + 308 to −2.23E−308 for negative numbers, 0, and +2.23E−308 to +1.79E + 308 for positive numbers.
xs:float This type represents an approximate single-precision floating point value per the IEEE 754–1985 standard. The format for values of this type is nEe, where n is a decimal mantissa followed by the letter E or e and an exponent. The value represents n·10 e . The range for xs:float values is approximately −3.4028e + 38 to −1.401298E−45 for negative numbers, 0, and +1.401298E−45 to +3.4028e + 38 for positive numbers. The special values −INF and + INF represent negative and positive infinity. SQL Server does not support the XQuery-specified special value NaN, which stands for “not a number.” A valid xs:float value is 1.98E + 2.
xs:int This type represents a 32-bit signed integer in the range −2147483648 to +2147483647.
xs:integer This type represents an integer value up to 28 digits in length. A valid xs:integer value is 76372.
xs:long This type represents a 64-bit signed integer in the range −9223372036854775808 to +9223372036854775807.
xs:negativeInteger This type represents a negative nonzero integer value derived from the xs:integer type. It can be up to 28 digits in length.
xs:nonNegativeInteger This type represents a positive or zero integer value derived from the xs:integer type. It can be up to 28 digits in length.
xs:nonPositiveInteger This type represents a negative or zero integer value derived from the xs:integer type. It can be up to 28 digits in length.
xs:positiveInteger This type represents a positive nonzero integer value derived from the xs:integer type. It can be up to 28 digits in length.
xs:short This type represents a 16-bit signed integer in the range −37268 to +32767.
xs:unsignedByte This type represents an unsigned 8-bit integer in the range 0 to 255.
xs:unsignedInt This type represents an unsigned 32-bit integer in the range 0 to +4294967295.
xs:unsignedLong This type represents an unsigned 64-bit integer in the range 0 to +18446744073709551615.
xs:unsignedShort This type represents an unsigned 16-bit integer in the range 0 to +65535.
String Types
xs:ENTITIES This type is a space-separated list of ENTITY types.
xs:ENTITY This type is equivalent to the ENTITY type from the XML 1.0 standard. The lexical space has the same construction as an xs:NCName.
xs:ID This type is equivalent to the ID attribute type from the XML 1.0 standard. An xs:ID value has the same lexical construction as an xs:NCName.
xs:IDREF This type represents the IDREF attribute type from the XML 1.0 standard. The lexical space has the same construction as an xs:NCName.
xs:IDREFS This type is a space-separated list of IDREF attribute types.
xs:language This type is a language identifier string representing natural language identifiers as specified by RFC 3066 (www.ietf.org/rfc/rfc3066.txt). A complete list of language codes is maintained by the IANA registry at www.iana.org/assignments/language-subtag-registry. Language identifiers must conform to the regular expression pattern [a-zA- Z]{1,8}(−[a-zA-Z0-9]{1,8})*. An example of a valid language identifier is tlh, which is the identifier for the Klingon language.
xs:Name This type is an XML name string. A name string must match the XML- specified production for Name. Per the standard, a Name must begin with a letter, an underscore, or a colon, and may then contain a combination of letters, numbers, underscores, colons, periods, hyphens, and various other characters designated in the XML standard as combining characters and extenders. Refer to the XML standard at www.w3.org/TR/2000/WD-xml-2e-20000814#NT-Name for specific information about these additional allowable Name characters.
xs:NCName This type is a noncolonized name. The format for an xs:NCName is the same as for xs:Name, but without colon characters.
xs:NMTOKEN This type is an NMTOKEN type from the XML 1.0 standard. An xs:NMTOKEN value is composed of any combination of letters, numbers, underscores, colons, periods, hyphens, and XML combining characters and extenders.
xs:NMTOKENS This type is a space-separated list of xs:NMTOKEN values.
xs:normalizedString This type is an XML whitespace-normalized string, which is one that does not contain the whitespace characters #x9 (tab), #xA (line feed), or #xD (carriage return).
xs:string This type is an XML character string.
xs:token This type is an XML whitespace-normalized string with the following additional restrictions on #x20 (space) characters: (1) it can have no leading or trailing spaces, and (2) it cannot contain any sequences of two space characters in a row.

9781430245964_AppB-01.jpg

Figure B-1.  XQuery data type system

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset