About collection types v15
The most commonly known type of collection is an array. In EDB Postgres Advanced Server, the supported collection types are:
- Associative arrays (formerly called index-by-tables in Oracle)
- Nested tables
- Varrays
Defining the collection type
To set up a collection:
- Define a collection of the desired type. You can do this in the declaration section of an SPL program, which results in a local type that you can access only in that program. For nested table and varray types, you can also do this using the
CREATE TYPE
command, which creates a persistent, standalone type that any SPL program in the database can reference. - Declare variables of the collection type. The collection associated with the declared variable is uninitialized at this point if no value assignment is made as part of the variable declaration.
Initializing a null collection
- Uninitialized collections of nested tables and varrays are null. A null collection doesn't yet exist. Generally, a
COLLECTION_IS_NULL
exception is thrown if a collection method is invoked on a null collection. - To initialize a null collection, you must either make it an empty collection or assign a non-null value to it. Generally, a null collection is initialized by using its constructor.
Adding elements to an associative array
- Uninitialized collections of associative arrays exist but have no elements. An existing collection with no elements is called an empty collection.
- To add elements to an empty associative array, you can assign values to its keys. For nested tables and varrays, generally its constructor is used to assign initial values to the nested table or varray. For nested tables and varrays, you then use the
EXTEND
method to grow the collection beyond its initial size set by the constructor.
Limitations
Multilevel collections (that is, where the data item of a collection is another collection) aren't supported.
Columns of collection types aren't supported.
For example, you can create an array
varchar2_t
, but you can't create a table using arrayvarchar2_t
as a column data type.