Type Hierarchy

Subtype-Substitution Rule Exceptions

SQL for Oracle NoSQL Database defines a subtype-supertype relationship among the types such that types are arranged in a hierarchy. For example, every type is a subtype of ANY. Any atomic type is a subtype of AnyAtomic. Integer is a subtype of Long. An array is a subtype of JSON if its element type is JSON or another subtype of JSON.

A data item is an instance of a type (T) if the data item's type is (T) or a subtype of (T).

This relationship is important because the usual subtype-substitution rule is supported by SQL for Oracle NoSQL Database. If an operation expects input items of type (T), or produces items of type (T), then it can also operate on or produce items of type (S) if (S) is a subtype of (T). (There is an exception to this rule. See Subtype-Substitution Rule Exceptions).

The following figure illustrates this data hierarchy. Dotted boxes in the figure represent collections of types.

In addition to the subtype relationships described here, the following relationships are also defined:

Subtype-Substitution Rule Exceptions

Ordinarily, if an operation expects input items of type (T), or produces items of type (T), then it can also operate on or produce items of type (S) if (S) is a subtype of (T). However, there are two exceptions to this rule.

The first exception concerns numeric values. Double and Float are subtypes of Number. However, Double and Float include three special values: NaN (not a number), positive infinity, and negative infinity. These values are not in the domain of Number. Therefore, an operation that expects a Number value will also work with Double/Float values as long as these values are not one of the three special values. If one of the three special values are used with Number, and error is raised.

Secondly, items whose type is a proper subtype of Array(JSON) or Map(JSON) cannot be used as:

  • record/map field values if the field type is JSON, Array(JSON) or Map(JSON); or

  • elements of arrays whose element type is JSON, Array(JSON) or Map(JSON).

This is in order to disallow strongly type data to be inserted into JSON data.

For example, consider a JSON document which is a map value whose associated type is Map(JSON). The document may contain an array whose values contain only integers. However, the type associated with the array cannot be Array(integer), it must be Array(JSON). If the array had type Array(integer), the user would not be able to add any non-integer values to it.