Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   Data Types and Expressions >

Collection Subquery

You can use a Collection Subquery to create a MULTISET collection from the results of a subquery. Only Dynamic Server supports this syntax, which is an extension to the ANSI/ISO standard for SQL.

Syntax

Read syntax diagramSkip visual syntax diagramCollection Subquery:
 
    (1)
|---------MULTISET--(--+-subquery----------------------+--)-----|
                       '-SELECT ITEM--singleton_select-'
 
Notes:
  1. Informix extension

Element Description Restrictions Syntax
singleton
_select
Subquery returning exactly one row Subquery cannot repeat the SELECT keyword, nor include the ORDER BY clause SELECT, p. SELECT
subquery Embedded query Cannot contain the ORDER BY clause SELECT, p. SELECT

Usage

The MULTISET and SELECT ITEM keywords have the following significance:

You can use a collection subquery in the following contexts:

The following restrictions apply to a collection subquery:

A collection subquery returns a multiset of unnamed ROW data types. The fields of this ROW type are elements in the projection list of the subquery. Examples that follow access the tables and the ROW types that these statements define:

CREATE ROW TYPE rt1 (a INT);
CREATE ROW TYPE rt2 (x int, y rt1);
CREATE TABLE tab1 (col1 rt1, col2 rt2);
CREATE TABLE tab2 OF TYPE rt1;
CREATE TABLE tab3 (a ROW(x INT));

The following examples of collection subqueries return the MULTISET collections that are listed to the right of the subquery.

Collection Subquery Resulting Collections
MULTISET (SELECT * FROM tab1)... MULTISET(ROW(col1 rt1, col2 rt2))
MULTISET (SELECT col2.y FROM tab1)... MULTISET(ROW(y rt1))
MULTISET (SELECT * FROM tab2)... MULTISET(ROW(a int))
MULTISET(SELECT p FROM tab2 p)... MULTISET(ROW(p rt1))
MULTISET (SELECT * FROM tab3)... MULTISET(ROW(a ROW(x int)))

The following is another collection subquery:

SELECT f(MULTISET(SELECT * FROM tab1 WHERE tab1.x = t.y))
   FROM t WHERE t.name = 'john doe';

The following collection subquery includes the UNION operator:

SELECT f(MULTISET(SELECT id FROM tab1 
UNION
SELECT id FROM tab2 WHERE tab2.id2 = tab3.id3)) FROM tab3;
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]