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

What Is an Operation?

Universal Server provides the following types of operations to operate on data types:

Operators and Operator Functions

Universal Server provides the following types of operators for expressions in SQL statements:

The database server provides special SQL-invoked functions, called operator functions, that implement operators. An operator function processes one to three arguments and returns a value. When an SQL statement contains an operator, the database server automatically invokes the associated operator function. This association between an operator and an operator function is called operator binding.

The versions of the operator functions that Universal Server provides handle the built-in data types. You can write a new version of an operator function to change the functionality of an operator or to provide the operator on a data type that is not built into the database server. If you write a new version of an operator function, follow these rules:

Arithmetic Operators

Universal Server provides operator functions for the arithmetic operators that Figure 2-4 shows.

Arithmetic Operator Operator Function Figure 2-4
Operator Functions for
Arithmetic Operators

+ (binary)

plus()

- (binary)

minus()

*

times()

/

divide()

+ (unary)

positive()

- (unary)

negate()

When an SQL statement contains an arithmetic operator, the database server automatically invokes the associated operator function. All operator functions in Figure 2-4 except positive() and negate() take two arguments; the positive() and negate() functions take only one argument. All these operator functions can return any data type.

Text Operators

Universal Server also provides operator functions for the text operators that Figure 2-5 shows.
Text Operator Operator Function Figure 2-5
Operator Functions for
Text Operators

LIKE

like()

MATCHES

matches()

||

concat()

When an SQL statement contains a text operator, the database server automatically invokes the associated operator function. The like() and matches() functions take two or three arguments and must return a Boolean value. The concat() function takes two arguments and can return any data type.

For information on syntax and use of the LIKE and MATCHES operators, see the description of the Condition segment in the Informix Guide to SQL: Syntax.

Relational Operators

Universal Server provides operator functions for the relational operators that Figure 2-6 shows.

Relational Operator Operator Function Figure 2-6
Operator Functions for
Relational Operators

=

equal()

<> and !=

notequal()

>

greaterthan()

<

lessthan()

>=

greaterthanorequal()

<=

lessthanorequal()

When an SQL statement contains a relational operator, the database server automatically invokes the associated operator function. All operator functions in Figure 2-6 take two arguments and must return a Boolean value. For more information on relational operators, see the description of the Relational Operator segment in the Informix Guide to SQL: Syntax.

For end users to be able to use values of a new data type with relational operators, you must write new relational-operator functions that can handle the new data type. In these functions, you can:

The relational-operator functions are strategy functions for the built-in secondary access method, a generic B-tree. For more information, see "The Generic B-Tree Index".

Built-In Functions

Universal Server provides special SQL-invoked functions, called built-in functions, that provide some basic mathematical operations. Figure 2-7 shows the built-in functions that you can overload.

Figure 2-4 needs to be reviewed!!

Figure 2-7
Built-In Functions That You Can Overload

(1 of 2)

Built-In Function Number of Parameters Parameter Types

abs()

1

real number

mod()

2

integer-number expression, integer-number expression

pow()

2

real-number expression,
real-number expression

root()

1 or 2

real-number expression
[, real-number expression]

round()

1 or 2

expression
[, literal integer]

sqrt()

1

real-number expression

trunc()

1 or 2

expression
[, literal integer]

exp(), log(), logn()

1

positive real-number expression

cos(), sin(), tan()

1

numeric expression

acos(), asin(), atan()

1

numeric expression

atan2()

2

numeric expression,
numeric expression

hex()

1

integer expression

length(), char_length(), character_length(), octet_length()

1

character string

user()

0

None

current()

0

None

dbservername(), sitename()

0

None

today()

0

None

extend()

1

date/time expression

The following table lists the built-in functions you cannot overload.

cardinality()

month()

date()

trim()

day()

weekday()

dbinfo()

year()

mdy()

OL/Optical
The following table lists the built-in functions for the INFORMIX-OnLine/Optical product that you cannot overload.

descr()

volume()

family()

Universal Server provides versions of the built-in functions that handle the built-in data types. You can write a new version of a built-in function to allow the function to operate on your new opaque data type. If you write a new version of a built-in function, make sure you follow these rules:

For more information on the built-in functions, see the description of the Expression segment in the Informix Guide to SQL: Syntax.

Aggregate Functions

The database server provides special SQL-invoked functions, called aggregate functions, that take values that depend on all the rows that the query selects; they return information about these values, not the actual values themselves. Universal Server provides the following aggregate functions:

For more information on aggregate functions, see the description of the Expression segment in the Informix Guide to SQL: Syntax.

End-User Routines

The database server provides special SQL-invoked functions and procedures, called end-user routines, that implement tasks you define for end users to use in expressions of SQL statements. These routines provide additional functionality that an end user might need to work with an existing or new data type. An end-user routine can be either of the following:

Once you have written the end-user routines, you must register them in the database as you do support functions. Use the CREATE FUNCTION statement to register end-user functions. Use the CREATE PROCEDURE statement to register end-user procedures. You must also use the GRANT statement to grant the Execute privilege to those users who have permission to call the end-user routines. For more information on how to write an end-user routine, see Extending INFORMIX-Universal Server: User-Defined Routines.




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