Extending Informix-Universal Server: Data Types
Chapter 3: Creating User-Defined Casts
Home
Contents
Index
Master Index
New Book
What Is a User-Defined Cast?
Create a user-defined cast to perform data conversion from one data type to another. You create a user-defined cast with the
CREATE CAST
statement, which registers the cast in the database.
The database server provides casts between most of the built-in data types. You can create user-defined casts to perform conversions between most data types, including opaque types, distinct types, row types, and built-in types. User-defined casts are generally used to provide type conversions for the following extended data types:
Opaque data types
When you create an opaque data type, you define casts to handle conversions between the internal and external representations of the opaque type. You might also create casts to handle conversions between the new opaque type and other data types in the database.
For information about how to create and register casts for opaque data types, see
"Creating the Casts"
.
Distinct data types
A distinct type cannot be directly compared to its source type. However, the database server automatically registers explicit casts from the distinct type to the source type and vice versa. Although a distinct type inherits the casts and functions of its source type, the casts and functions that you define on a distinct type are not available to its source type. You might also create casts on distinct types to handle conversions between the new distinct type and other data types in the database.
For more information and examples that show how you can create and use casts for distinct types, see the chapter on casting in the
Informix Guide to SQL: Tutorial
.
Named row types
In most cases, you can explicitly cast a named row type to another row type value without having to create the cast. However, in some cases, you might want to create a cast that allows for comparisons between a named row type and some other data type.
For information about casting between named row types and unnamed row types, see the chapter on casting in the
Informix Guide to SQL: Tutorial
.
You cannot create a user-defined cast that includes any of the following data types as either the source type or target type for the cast:
Collection data types:
LIST
,
MULTISET
, or
SET
Unnamed row types
Smart-large-object data types:
BLOB
or
CLOB
Simple-large-object data types:
BYTE
or
TEXT
Extending Informix-Universal Server: Data Types
, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.