- Index

< Previous |  | Next >

# CREATE STREAM Statement

## Syntax

    CREATE STREAM stream_identifier
      named_schema_identifier|(anonymous_schema)
      [WITH PARAMETERS (
        parameter_name = "parameter_value" [, ...] )]
    [SELECT field_identifier[, ...]
      FROM ... [WHERE ...} INTO stream_identifier];

Or

    CREATE STREAM stream_identifier AS
      stream_expression;

Or

    CREATE STREAM stream_identifier;
    stream_expression INTO stream_identifier;

Or

    CREATE STREAM stream_identifier (
      field_identifier field_type[, ...]);
    SELECT field_identifier[, ...]
      FROM ... [WHERE ...} INTO stream_identifier;

### Substitutable Field

`stream_identifier`

  A unique identifier (name) for the stream.

`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. For example:

      CREATE SCHEMA SymbolSchema (ID int, Symbol string, Price double);
      CREATE STREAM Input1 SymbolSchema;

  This input stream statement is equivalent to the following, using an anonymous schema:

      CREATE STREAM Input1 (ID int, Symbol string, Price double);

`anonymous_schema`

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

      field_identifier field_type[, ...]

  Here are two examples:

      CREATE STREAM Input2
        (ID int, Symbol string, Price double);

      CREATE STREAM Input3
        (ss SymbolSchema, Quantity int);

  Note that the second anonymous schema includes a field that references the previously-defined named schema. It is equivalent to:

      ss (ID int, Symbol string, Price double), Quantity int

`stream_expression`

  Any StreamSQL statement, for example, a SELECT ... FROM ... [WHERE ...] statement or a VJOIN statement, that returns a stream.

`field_identifier`

  The unique identifier (name) for a field in the schema associated with the stream. Note that in the third syntax for creating a stream, the field_identifier values must be the same in both the CREATE STREAM and SELECT statements.

`field_type`

  One of the supported StreamBase data types as described in StreamBase Data Types. With a string type, the maximum length must be specified.

`parameter`

  A parameter takes the form:

  `parameter_name` `parameter_value`

  `parameter_name`

    The name of a StreamBase parameter appropriate to the statement

  `parameter_value`

    A quoted value for the parameter, which if a string must include escaped quotes

## Discussion

The CREATE STREAM statement defines an intermediate, named stream that is available only within a StreamBase module. They are different from input and output streams, by which event messages enter and leave the module, and which are accessible outside the module. Named streams are not accessible to StreamBase applications or network clients that run outside of the module.

There are several ways to define a named stream:

- The first approach names the stream and defines its content as a single statement; the field names and types associated with the stream are defined as part of the stream query.

- The second approach performs these two actions as separate statements; again the field names and types are defined within the stream query identified as the source of the stream.

- In the third approach, specify the schema as part of the stream declaration. The field identifier names, field types, and order of the target list entries in the associated stream query's SELECT statement must then match the schema fields in the stream definition. For example:

      CREATE INPUT STREAM source_stream_identifier (field_identifier_1 field_type_1);
      CREATE STREAM stream_identifier (field_identifier_1 field_type_1);
      SELECT field_identifier_1 FROM source_stream_identifier INTO stream_identifier;

  Note that the field identifier, which is the name of the field, must be the same in both the CREATE STREAM and SELECT clauses. The source stream identified in the FROM clause is a stream from which fields with the required names as types can be extracted. If necessary, use the AS clause to rename source stream fields. For example:

      CREATE INPUT STREAM source_stream_identifier (field_identifier_1 field_type_1);
      CREATE STREAM stream_identifier (field_identifier_2 field_type_1);
      SELECT field_identifier_1 AS field_identifier_2 FROM source_stream_identifier
        INTO stream_identifier

If you use the second approach to define a stream, StreamBase Studio issues a warning that the stream does not have a source until the SELECT clause is completed. A warning is not issued with the third approach, because the content of the stream is known.

## Related Topics

- CREATE OUTPUT STREAM Statement

- CREATE INPUT STREAM Statement

- SELECT Statement

- Using Named Schemas

Back to Top ^