|
Home > Documentation > CREATE OUTPUT STREAM Statement
CREATE OUTPUT STREAM Statement
Syntax
CREATE OUTPUT STREAM stream_identifier AS
stream_expression;
Or:
stream_expression => CREATE OUTPUT STREAM stream_identifier;
Or:
CREATE OUTPUT STREAM stream_identifier;
stream_expression INTO stream_identifier;
Or:
CREATE OUTPUT STREAM stream_identifier (
field_identifier field_type[, ...]);
SELECT field_identifier[, ...]
FROM ... [WHERE ...} INTO stream_identifier;
Substitutable Fields
stream_expression:
Any StreamSQL statement — for example, the SELECT ... FROM ... [WHERE ...] statement or a VJOIN statement — that returns a stream.
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:
int
| double
| bool
| timestamp
| string(length)
The data type contained in a specified field. StreamSQL supports the following data types: int, string, double, bool, and timestamp. With a string type, the maximum length must be specified.
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 may be optionally included within the stream declaration. If the stream's fields are not included in the declaration, an typecheck error will be raised 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 may 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
|