Home | Previous Page | Next Page   Selecting Data from Complex Types (IDS) >

Selecting from a Collection

This section describes how to query columns that are defined on collection types. A collection type is a complex data type in which each collection value contains a group of elements of the same data type. For a detailed description of collection data types, see the IBM Informix: Database Design and Implementation Guide. For information about how to access the individual elements that a collection contains, see Handling Collections in SELECT Statements (IDS).

Figure 144 shows the manager table, which is used in examples throughout this section. The manager table contains both simple and nested collection types. A simple collection is a collection type that does not contain any fields that are themselves collection types. The direct_reports column of the manager table is a simple collection. A nested collection is a collection type that contains another collection type. The projects column of the manager table is a nested collection.

Figure 144.
CREATE TABLE manager
(
   mgr_name        VARCHAR(30),
   department      VARCHAR(12),
   direct_reports  SET(VARCHAR(30) NOT NULL),
   projects        LIST(ROW(pro_name VARCHAR(15),
                     pro_members SET(VARCHAR(20) NOT NULL) 
                     ) NOT NULL)
)

A query on a column that is a collection type returns, for each row in the table, all the elements that the particular collection contains. For example, Figure 145 shows a query that returns data in the department column and all elements in the direct_reports column for each row of the manager table.

Figure 145. Query
SELECT department, direct_reports FROM manager

Figure 146. Query Result
department      marketing
direct_reports  SET {Smith, Waters, Adams, Davis, Kurasawa}

department      engineering
ddirect_reports  SET {Joshi, Davis, Smith, Waters, Fosmire, Evans, Jones}

department      publications
direct_reports  SET {Walker, Fremont, Porat, Johnson}

department      accounting
direct_reports  SET {Baker, Freeman, Jacobs}

·
·
·

The output of a query on a collection type always includes the type constructor that specifies whether the collection is a SET, MULTISET, or LIST. For example, in Figure 146, the SET constructor precedes the elements of each collection. Braces ({}) demarcate the elements of a collection; commas separate individual elements of a collection.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]