CREATE SCHEMAschema_identifiernamed_schema_identifier|anonymous_schema;
-
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_identifierfield_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.
-
-
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.
-
This named schema contains two double fields.
-
This named schema contains a string field (tag) and a nested tuple field (nums).
-
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) );
-
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)
