Professional Documents
Culture Documents
Introduction:
User-defined ADTs:
Lists:
Traditional list operations:
• Head – returns the first element.
• Tail – returns the list obtained by removing the first element.
• Prepend – takes an element and inserts it as the first element in a list.
• Append – appends one list to another.
Queries over nested collections:
SELECT F.filmno
FROM Films F
WHERE CARDINALITY(F.stars) > 2
A nested relation, Films
Filmno Title Stars
50 Casablanca {Bogart,Bergman}
60 Earth Worms Are Juicy {Herbert,Wanda}
SELECT F.filmno,F.title,set_gen(F.star)
FROM Films_flat F
GROUP BY F.filmno, F.title
The set_gen operator collects the set of star values in a partition and creates a set_valued
object. This operation is called nesting.
INHERITANCE
• Inheritance is supported directly and allows type definitions to be reused and
refined easily.
• In object-database systems, it can be used in two ways: for reusing and refining
types and for creating hierarchies of collections of similar but not identical
objects.
Defining types with Inheritance:
CREATE TYPE theatrecafe_t UNDER theatre_t (menu text);
Supertype – theatre_t
Subtype – theatrecafe_t.
An object of the subtype is also considered to be an object of the supertype.
The substitution principle: Given a supertype A and a subtype B, it is always possible to
substitute an object of type B into a legal expression written for objects of type A,
without producing type errors.
Binding methods:
Nowshowing.deref(theatre).name.