Row data types

A row data type can be thought of as a row of columns, of varying data types, stored in a single database table column.

Row data types follow essentially the same rules as database tables. The columns within a row data type are called fields. They can be almost any data type, including other extended data types and built-in data types, such as smart large objects. You can access fields individually by using SQL statements.

To create a row data type, you specify:
  • a unique name for the whole row type
  • a unique name for each field
  • a data type for each field.
The following diagram illustrates a row type named address_t in a column named Address.
Figure 1: Sample row data type

begin figure description - This figure is described in the surrounding text. - end figure description

Instead of having additional columns in the Address table, the row data type groups data that is most often accessed together in one column. The table Address consists of the columns Name(LVARCHAR(30)), Address(address_t), and Dependents(SET(LVARCHAR)). The row data type address_t consists of the named fields Street(LVARCHAR(20)), City(LVARCHAR(20)), State(CHAR(2)), and Zip_code(INTEGER).

Like collection data types, row data types allow you to reconfigure your database table. Use a row type if you have data of differing data types that group naturally into a single column. You can further group your data if you include a collection or another row data type as a field within your row data type.

Row data types can be useful for handling smart large objects. For example, if a row data type has a field that is an opaque data type containing an image in a smart large object, the other fields of the row data type could contain additional information about the image.

For best performance, use row data types if most user queries access all or most of the fields of the row data type.

You can use row data types to create inheritance hierarchies, allowing you to write selective routines. A child row data type inherits the fields of its parent and can be passed to all routines defined for the parent; however, the parent data type cannot be passed to routines defined for the child data type.

For a discussion about row data types, see the Informix® Guide to SQL: Tutorial.