![]() |
|
Home | Contents | Index | Master Index | New Book | ![]() |
![]() |
Built-In Data TypesUniversal Server provides the following built-in data types:For a description of each of these data types, refer to the appropriate entry in "Supported Data Types".
![]() For information on how to use time data types, see "Using DATE, DATETIME, and INTERVAL Data".
An INTERVAL column can hold a value that represents the difference between two DATETIME values or the difference between (or sum of) two INTERVAL values. In either case, the result is a span of time, which is an INTERVAL value. On the other hand, if you add or subtract an INTERVAL value from a DATETIME value, another DATETIME value is produced because the result is a specific time. Figure 2-3 indicates the range of expressions that you can use with DATE, DATETIME, and INTERVAL data, along with the data type that results from each expression.
Figure 2-3
(1 of 2)
DATE
-
DATETIME
INTERVAL
DATETIME
-
DATE
INTERVAL
DATE
+ or -
INTERVAL
DATETIME
DATETIME
-
DATETIME
INTERVAL
DATETIME
+ or -
INTERVAL
DATETIME
INTERVAL
+
DATETIME
DATETIME
INTERVAL
+ or -
INTERVAL
INTERVAL
DATETIME
-
CURRENT
INTERVAL
CURRENT
-
DATETIME
INTERVAL
INTERVAL
+
CURRENT
DATETIME
CURRENT
+ or -
INTERVAL
DATETIME
DATETIME
+ or -
UNITS
DATETIME
INTERVAL
+ or -
UNITS
INTERVAL
INTERVAL
* or /
NUMBER
INTERVAL
If the second DATETIME value has fewer fields than the first, the shorter value is extended automatically to match the longer one. (See the discussion of the EXTEND function in the Expression segment in Chapter 1 of the Informix Guide to SQL: Syntax.) In the following example, subtracting the DATETIME YEAR TO HOUR value from the DATETIME YEAR TO MINUTE value results in a positive interval value of 60 days, 1 hour, and 30 minutes. Because minutes were not included in the second value, the database server sets the minutes for the result to 0. If the second DATETIME value has more fields than the first (regardless of whether the precision of the extra fields is larger or smaller than those in the first value), the additional fields in the second value are ignored in the calculation. In the following expression (and result), the year is not included for the second value. Therefore, the year is set automatically to the current year, in this case 1994, and the resulting INTERVAL is negative, indicating that the second date is later than the first.
Manipulating DATETIME with INTERVAL ValuesINTERVAL values can be added to or subtracted from DATETIME values. In either case, the result is a DATETIME value. If you are adding an INTERVAL value to a DATETIME value, the order of values is unimportant; however, if you are subtracting, the DATETIME value must come first. Adding or subtracting an INTERVAL value simply moves the DATETIME value forward or backward in time. The expression shown in the following example moves the date ahead three years and five months:
The EXTEND function allows you to explicitly increase the DATETIME precision from YEAR TO DAY to YEAR TO MINUTE. This allows the database server to perform the calculation, with the resulting extended precision of YEAR TO MINUTE.
Figure 2-4
DATE - DATETIME
INTERVAL
DATETIME - DATE
INTERVAL
DATE + or - INTERVAL
DATETIME
Although you can interchange DATE and DATETIME values in many situations, you must indicate whether a value is a DATE or a DATETIME data type. A DATE value can come from the following sources:
When you represent DATE and DATETIME values as quoted character strings, the fields in the strings must be in proper order. In other words, when a DATE value is expected, the string must be in DATE format and when a DATETIME value is expected, the string must be in DATETIME format. For example, you can use the string
You can customize the DATE format that
the database server expects with the DBDATE
and GL_DATE environment variables. You can
customize the DATETIME format that the database server
expects with the DBTIME and GL_DATETIME
environment variables. For more information on these environment variables,
see the Guide to GLS Functionality. You also can subtract one DATE value from another DATE value, but the result is a positive or negative INTEGER value rather than an INTERVAL value. If an INTERVAL value is required, you can either convert the INTEGER value into an INTERVAL value or one of the DATE values into a DATETIME value before subtracting. For example, the following expression uses the DATE() function to convert character string constants to DATE values, calculates their difference, and then uses the UNITS DAY keywords to convert the INTEGER result into an INTERVAL value: If you need YEAR TO MONTH precision, you can use the EXTEND function on the first DATE operand, as shown in the following example:
Result: INTERVAL (39-01) YEAR TO MONTH
Note the use of numeric qualifiers to alert the database server that the MINUTE and FRACTION in the first value and the SECOND in the second value exceed the default number of digits. When you add or subtract INTERVAL values, the second value cannot have a field with greater precision than the first. The second INTERVAL, however, can have a field of smaller precision than the first. For example, the second INTERVAL can be HOUR TO SECOND when the first is DAY TO HOUR. The additional fields (in this case MINUTE and SECOND) in the second INTERVAL value are ignored in the calculation.
In this example, 15 * 2.5 = 37.5 minutes, 30 * 2.5 = 75 seconds, and 2 * 2.5 = 5 fraction(4). The 0.5 minute is converted into 30 seconds and 60 seconds are converted into 1 minute, which produces the final result of 38 minutes, 45 seconds, and 0.0005 of a second. The results of any calculation include the same amount of precision as the original INTERVAL value.
Figure 2-5 shows the different large-object data types that Universal Server supports.
For the relative advantages and disadvantages of using simple and smart large objects, see Chapter 9, "Implementing Your Data Model," of the Informix Guide to SQL: Tutorial.
Universal Server supports the following smart-large-object data types:
Universal Server stores smart large objects in sbspaces. An sbspace is a logical storage area that contains one or more chunks that only store BLOB and CLOB data. For information on how to define sbspaces, see the INFORMIX-Universal Server Administrator's Guide. When you define a BLOB or CLOB column, you can determine the following large-object characteristics:
When you access a smart-large-object column with an SQL statement, the database server does not send the actual BLOB or CLOB data. Instead, it establishes a pointer to the data and returns this pointer. The client application can then use this pointer to perform the open, read, or write operations on the smart large object. To access a BLOB or CLOB column from within a client application, use one of the following application programming interfaces (APIs):
For information on using smart large objects, see Chapter 9, "Implementing Your Data Model," of the Informix Guide to SQL: Tutorial and the Data Type and Expression segments in the Informix Guide to SQL: Syntax.
Unlike smart large objects (see page 2-17), simple large objects do not support random access to the data. When you transfer a simple large object between a client application and the database server, you must transfer the entire BYTE or TEXT value. If the data does not fit into memory, you must store it in an operating-system file and then retrieve it from that file. Universal Server stores simple large objects in blobspaces. A blobspace is a logical storage area that contains one or more chunks that only store BYTE and TEXT data. For information on how to define blobspaces, see the INFORMIX-Universal Server Administrator's Guide.
|
![]() |
![]() |