8 Schema Flexibility with JSON Columns in Duality Views

Including columns of JSON data type in tables that underlie a duality view lets applications add and delete fields, and change the types of field values, in the documents supported by the view. The stored JSON data can be schemaless or JSON Schema-based (to enforce particular types of values).

When schemaless, the values such fields can be of any JSON-language type (scalar, object, array). This is in contrast to the fields generated from scalar SQL columns, which are always of a predefined type (and are always present in the documents).

When you define a duality view, you can declaratively choose the kind and degree of schema flexibility you want, for particular document parts or whole documents.

The values of a JSON column can either be embedded in documents supported by a duality view, as the values of fields declared in the view definition, or merged into an existing document object by simply including them in the object when a document is inserted or updated.

Embedding values from a JSON-type column into a document is the same as embedding values from a column of another type, except that there's no conversion from SQL type to JSON. The value of a field embedded from a JSON-type column can be of any JSON-language type, and its type can be constrained to conform to a JSON schema.

Fields that are merged into a document aren't mapped to individual columns. Instead, for a given table they're all implicitly mapped to the same JSON-type object column, called a flex column. A flex column thus has data type JSON (OBJECT), and no field is mapped to it in the view definition.

A table underlying a duality view can have both a flex column and nonflex JSON-type columns. Fields stored in the flex column are merged into the document object produced by the table, and fields stored in the nonflex columns are embedded into that object.

_________________________________________________________