CREATE SCHEMA Statement

Syntax

CREATE SCHEMA schema_identifier 
  named_schema_identifier|anonymous_schema
;

Substitutable Field

schema_identifier

A unique name for the schema.

named_schema_identifier

The identifier of a previously-defined named schema. Imports all of the named schema's fields. No parentheses are required, and no other fields are permitted.

anonymous_schema

A schema definition, delimited by parentheses, in the following format:

(field_definition [, ...])
field_definition

A field definition takes the form:

field_identifier field_type

field_identifier

A unique name for a field in the schema associated with the stream. For table indexes, if the field references a named schema, the entire schema is used as the key.

field_type

One of the supported StreamBase data types.

Example

The following statements create named schemas. The first example presents a schema definition and names it Schema1. The second example defines its schema by referencing the first schema by name:

CREATE SCHEMA Schema1 (ID int, Symbol string(5), Price double);
CREATE SCHEMA Schema2 Schema1;

Discussion

Use CREATE SCHEMA to create a named schema. Unlike a schema defined within a stream or table, a named schema is defined at the application level, and can be referenced by any component in the application that takes a schema.

For example:

CREATE SCHEMA point (x double, y double);                         [1]
CREATE SCHEMA nested (tag string(12), nums (a int, y double));    [2] 
CREATE INPUT STREAM in (comment string(512), p point);            [3]
CREATE OUTPUT STREAM out;                    
SELECT point(1,2) AS mixed FROM in INTO out;                      [4]

The following notes refer to the line numbers in brackets in the example above.

  1. This named schema contains two double fields.

  2. This named schema contains a string field (tag) and a nested tuple field (nums).

  3. This input stream includes the named schema, point, by reference. It is equivalent to:

    CREATE INPUT STREAM in (comment string(512), (x double, y double) );
    
  4. This statement demonstrates another way to use a named schema: its identifier can be used to invoke the schema_constructor function to generate a tuple. Here, the point() function creates a tuple with the values 1 and 2. In this case, the int arguments are coerced to doubles, conforming to the named schema, like this:

    mixed(1.0,2.0)