- Index

< Previous |  | Next >

# CREATE OUTPUT STREAM Statement

## Syntax

    CREATE [PUBLIC] OUTPUT STREAM stream_identifier
      [WITH OUTPUT PREDICATE predicate]
      [WITH PARAMETERS {
        parameter_name = "parameter_value" [, ...]} ] AS
      stream_expression;

Or

    stream_expression =>
      CREATE [PUBLIC] OUTPUT STREAM
        [WITH OUTPUT PREDICATE predicate] stream_identifier;

Or

    CREATE [PUBLIC] OUTPUT STREAM stream_identifier
      [WITH OUTPUT PREDICATE predicate];
       stream_expression INTO stream_identifier;

Or

    CREATE [PUBLIC] OUTPUT STREAM stream_identifier (
      field_identifier field_type[, ...])
      [WITH OUTPUT PREDICATE predicate];
    SELECT field_identifier[, ...]
      FROM ... [WHERE ...} INTO stream_identifier;

### Substitutable Fields

stream_expression

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

stream_identifier

  A unique identifier (name) for the output stream.

field_identifier

  The unique identifier (name) for a field in the schema associated with the stream. Note that in the fourth syntax for creating an output stream, the `field_identifier` values must be the same in both the CREATE OUTPUT 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.

predicate

  A clause that selects tuples emitted on the output stream. To be selected, a tuple must satisfy the restriction, or restrictions, included in the `predicate`. If the `predicate` evaluates to true, the tuple is emitted.

`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

In StreamSQL, a stream query (stream expression) must be used to define the content of an Output Stream. There are multiple ways to define an Output Stream: create the stream and define its stream query as a single statement, or perform each of these steps as separate statements. There are two ways of using the each approach. With the second approach, the field names and types can be optionally included within the stream declaration. If the stream's fields are not included in the declaration, StreamBase Studio's StreamSQL application editor will raise an error stating that the stream does not have a source until the second statement that populates the stream has been written. If the stream's fields are included in the 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 field declarations included in the stream definition. For example,

    CREATE INPUT STREAM source_stream_identifier (field_identifier_1 field_type_1);
    CREATE OUTPUT 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 OUTPUT 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 OUTPUT 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 the optional WITH OUTPUT PREDICATE `predicate` clause is used, only tuples satisfying the predicate restriction(s) are emitted on the output stream. This clause (which is equivalent to the WHERE clause in a SELECT statement) can be used to restrict the tuples emitted on an output stream populated by a StreamSQL statement that does not include a WHERE clause. In this regard, it eliminates the need to add a SELECT statement for the sole purpose of filtering the emitted tuples.

Use the optional PUBLIC keyword to designate that this stream is to be available for dequeuing, no matter how deeply the module that contains this stream is nested in a complex application.

## Related Topics

- CREATE INPUT STREAM Statement

- CREATE STREAM Statement

- SELECT Statement

Back to Top ^