INFORMIX
Extending Informix-Universal Server: Data Types
Chapter 1: Extending Data Types
Home Contents Index Master Index New Book

Creating New Data Types

The extensible data type system of Universal Server allows you to:

Data Types That You Provide

You can define the following kinds of data types in Universal Server:

Together these data types are called extended data types. Universal Server stores information about extended data types in the sysxtdtypes and sysxtdtypeauth system catalog tables.

Figure 1-3 summarizes the user-defined data types that Universal Server provides.

Figure 1-3
User-Defined Data Types of Universal Server

Data Type Explanation

Distinct data type

Is stored in the same way as the source data type on which it is based, but has different casts and functions defined over it than those on the source type.

Opaque data type

Fundamental data type that the user defines. (A fundamental data type is atomic; that is, it cannot be broken into smaller pieces, and it can serve as the building block for other data types).

This section summarizes the kinds of data types that you can define to extend the Universal Server data type system. For more information, see the chapter on data types in the Informix Guide to SQL: Reference.

The Opaque Data Type

The opaque data type is a fundamental data type. However, unlike the other fundamental data types (the built-in data types), the internal structure of the opaque data type is not known to the database server. Therefore, when you define an opaque type, you must provide the following information:

    You define the support functions of the opaque type to tell the database server how to interact with this internal structure.

    You define operator functions, built-in functions, or end-user routines that handle the opaque type.

    The support functions of the opaque type also serve as casting functions.

You register an opaque data type with the CREATE OPAQUE TYPE statement. For more information, see Chapter 5, "Creating an Opaque Data Type," and Chapter 6, "Writing Support Functions."

A Distinct Data Type

A distinct type has the same internal structure as some existing data type. However, it has a distinct name and therefore distinct functions that make it different from its source type. When you define a distinct type, you provide the following information:

    The functions of the source data type tell the database server how to interact with this internal structure.

    You define operator functions, built-in functions, or end-user routines that handle the distinct type.

    The database server automatically creates explicit casts between the distinct type and its source type. However, because these two data types have the same internal format, this cast does not require a casting function. You can write casting functions to support data conversion between the distinct type and other data types in the database or to support implicit casts between the distinct type and its source type.

You create a distinct data type with the CREATE DISTINCT TYPE statement. Once you create the distinct type, you can use it anywhere that other data types are valid. For more information, refer to the description of this statement in the Informix Guide to SQL: Syntax.

A Named Row Type

A named row type has a group of one or more components called fields. Each field has a name and a data type. The fields of a row type can be any data type except SERIAL and SERIAL8. Some exceptions exist for the fields of a row type that are the TEXT or BYTE data type.

Named row types are identified by their names. When you define a named row type, you provide the following information:

    The database server uses the functions that are associated with each of the field types to determine how to interact with this internal structure.

    You define operator functions, built-in functions, or end-user routines that handle the distinct type.

You create a named row type with the CREATE ROW TYPE statement. Once you create the named row type, you can use the row-type name as a data type anywhere that other data types are valid. In addition, you can use this name to create type and table inheritance. For more information, see the description of this statement in the Informix Guide to SQL: Syntax.

DataBlade Module Data Types

In addition to the data types that you explicitly define, you can obtain new data types from an Informix DataBlade module. A DataBlade module might provide the data type, including any casts, operations, and secondary access methods, for an application-specific purpose. For more information on the DataBlade modules available, consult your Informix sales representative or refer to the user guides for the DataBlade modules.

Ways to Extend With New Data Types

You can extend the following data type information for an existing built-in or complex data type:

Extending Operations

To implement operations on an extended data type, you define an SQL-invoked function that performs the operation. You can write SQL-invoked functions to extend the following operations for an extended data type:

    An end-user routine can be either a function (which returns a value) or a procedure (which does not return a value).

You must register each SQL-invoked function in the database with the CREATE FUNCTION (or CREATE PROCEDURE) statement. For more information, see "How Do You Extend an Operation?".

Extending Operator Classes

The default operator class that Universal Server provides for the built-in secondary access method (a generic B-tree) handles only built-in data types and uses the relational operators (<, >, =, and so on) to order values.

You might want to extend an operator class to support an extended data type for the following reasons:

To implement an operator class, you define strategy and support functions that handle each extended data type you want to index. You must register this new operating class in the database with the CREATE OPCLASS statement. For more information, see Chapter 4, "Extending an Operator Class."

Creating Casts

Universal Server provides casts between the built-in data types that it provides. You might want to create additional casts to provide data conversion between:

If the two data types have the same internal structure, you create the cast with the CREATE CAST statement. If the two data types have different internal structures, you must define a casting function to perform the data conversion. You register the casting function with the CREATE FUNCTION statement and create the cast with the CREATE CAST statement. For more information on casts, see Chapter 3, "Creating User-Defined Casts."




Extending Informix-Universal Server: Data Types, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.