![]() |
|
An SQL-invoked function is a user-defined function that an end user can explicitly call in an SQL statement. You might write SQL-invoked functions to extend the functionality of an opaque data type in the following ways:
The SQL functions that the database server defines handle the built-in data types. For a user-defined data type to use any of these functions, you can write a version of the function that handles the UDT. (For more information on the details of writing user-defined functions, see Chapter 4, Developing a User-Defined Routine.)
The database server supports the following types of SQL-invoked functions that allow you to operate on data in expressions of SQL statements:
The database server provides the following types of operators for expressions in SQL statements:
Tip: The database server also provides relational operators. For more information on the relational operators and their operator functions, see Comparing Data.
The database server provides operator functions for the arithmetic operators (see Figure 6-1 on page 6-5) and text operators (see Figure 6-2 on page 6-5). The versions of the operator functions that database server provides handle the built-in data types. You can write a new version of one of these operator function to provide the associated operation on your new opaque data type.
If you write a new version of an operator function, make sure you follow these rules:
The database server provides special SQL-invoked functions, called built-in functions, that provide some basic mathematical operations. Figure 6-4 on page 6-8 shows the built-in functions that the database server defines. The versions of the built-in functions that database server provides handle the built-in data types. You can write a new version of a built-in function to provide the associated operation on your new opaque data type. If you write a new version of a built-in function, follow these rules:
For more information on built-in functions, see Built-In Functions.
The database server supports the following types of functions that allow you to compare data in expressions of SQL statements:
The database server supports the following relational operators on an opaque data type in the conditional clause of SQL statements:
Tip: The database server also uses the compare() function as the support function for the default B-tree operator class. For more information, see Extensions of the btree_ops Operator Class.
For more information on the conditional clause, see the Condition segment in the Informix Guide to SQL: Syntax. For more information on the compare() function, see Comparison Function for Opaque Data Types.
The database server provides operator functions for the relational operators that Figure 6-3 on page 6-6 shows. The versions of the relational-operator functions that the database server provides handle the built-in data types. You can write a new version of a relational-operator function to provide the associated operation on your new opaque data type.
If you write a new version of a relational-operator function, make sure you follow these rules:
You must define an equal() function to handle your opaque data type if you want to allow columns of this data type to be:
The equal() function can compare only bit-hashable data types; that is, a bit-wise compare can determine equality. This comparison means that two values are equal if they have the same internal representation. The database server uses a built-in hash function to perform this comparison.
If your opaque data type is not bit hashable, the database server cannot use its built-in hash function for the equality comparison. Therefore, you cannot use the opaque data type in the following cases:
For opaque types that are not bit hashable, specify the CANNOTHASH modifier in the CREATE OPAQUE TYPE statement.
Bit-hashable data types have the following property: if A = B, then hash(A) = hash(B), which means that A and B have identical bit representations. CANNOTHASH specifies that data type equality cannot be determined by a bit-wise compare.
The following requirements apply to support functions on nonhashable data types:
The compare() function is an SQL-invoked function that sorts the target data type. The database server uses the compare() function to execute the following clauses and keywords of the SELECT statement:
The database server also uses the compare() function to evaluate the BETWEEN operator in the condition of an SQL statement. For more information on conditional clauses, see the Condition segment in the Informix Guide to SQL: Syntax.
The database server provides versions of the compare() function that handle the built-in data types. For the database server be able to sort an opaque data type, you must define a compare() function that handles this opaque data type.
If you write a new version of a compare() function, make sure you follow these rules:
If your opaque data type is not bit hashable, the compare() function should generate an error so that the database server does not use the default compare() function.
The compare() function is also the support function for the default operator class of the B-tree secondary access method. For more information, see Generic B-Tree Index.