CREATE STREAM creates a new stream in Timeplus Proton. Streams are append-only data structures optimized for real-time data ingestion and querying.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/timeplus-io/proton/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
Parameters
The name of the stream to create. Can be qualified with database name as
db.stream_name.If specified, the statement will not raise an error if the stream already exists.
If specified, creates a temporary stream that exists only for the duration of the session.
The name of the column.
The data type of the column. Supported types include: int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64, string, datetime, datetime64, date, bool, array, map, tuple, and more.
Default value expression for the column. Can reference other columns or use functions.
Compression codec for the column. Examples: CODEC(ZSTD), CODEC(LZ4), CODEC(Delta, ZSTD).
Secondary index definition with syntax:
INDEX name expr TYPE type GRANULARITY valueCheck constraint with syntax:
CONSTRAINT name CHECK exprEngine
The storage engine to use. Default is
Stream(). Other engines include VersionedKV() for changelog streams.Clauses
Expression to determine how data is partitioned. Common pattern:
PARTITION BY to_YYYYMM(_tp_time)Primary key expression. Used for data organization and query optimization.
Expression defining the sort order within partitions. If not specified, defaults to PRIMARY KEY.
Expression for sampling. Typically uses a hash function on the primary key.
Time-to-live expression. Defines when data should be automatically deleted.
Syntax:
TTL _tp_time + INTERVAL 30 DAYSettings
Stream mode. Options:
append(default): Append-only streamchangelog_kv: Changelog stream with primary key for updates/deletesversioned_kv: Versioned key-value stream
Column name for versioning in changelog/versioned streams. Usually
_tp_time.Maximum size in bytes for the log store before old data is deleted.
Maximum age in milliseconds for data in the log store before deletion.
Examples
Basic Stream
Create a simple stream with basic columns:Stream with Default Values
Create a stream with default expressions:Stream with Primary Key
Create a changelog stream with primary key:Stream with TTL
Create a stream that automatically deletes data older than 30 days:Stream with Partitioning
Create a stream partitioned by month:CREATE RANDOM STREAM
CREATE RANDOM STREAM is a special variant that generates random data continuously. Useful for testing and development.Syntax
Parameters
Events per second to generate. Default is unlimited (generates as fast as possible).
Examples
Random Stream with Default Expressions
Querying Random Stream
Notes
- The
_tp_timecolumn is automatically added to all streams and contains the event time (ingestion time by default) - Streams are append-only by default. For update/delete support, use
mode='changelog_kv' - For versioned streams, specify
version_columnin SETTINGS - The default engine is
Stream()which provides high-performance streaming storage
See Also
- CREATE EXTERNAL STREAM - Connect to external data sources
- CREATE MATERIALIZED VIEW - Create materialized views
- INSERT - Insert data into streams
- SELECT - Query streams