|
Home > Documentation > CREATE STREAM Statement
CREATE STREAM Statement
Syntax
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 Fields
stream_expression:
Any StreamSQL statement, for example, a SELECT ... FROM ... [WHERE ...] statement or a VJOIN statement, that returns a stream.
stream_identifier:
A unique identifier (name) for the 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:
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
A stream (also referred to as a named stream) is a stream that is only available within a module; it is not accessible to other modules, or network clients; Input or Output Streams are accessible from outside the module.
There are three 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 field names and types 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 field declarations included 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 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 STREAM stream_identifier
(field_identifier_2 field_type_1);
SELECT field_identifier_1 AS field_identifier_2
FROM source_stream_identifier
INTO stream_identifier
When using the second approach to define a stream, a warning will be issued that the stream does not have a source until the SELECT clause is completed. When using the third approach, since the content of the stream is known, a warning will not be issued.
|