Specify one or more columns that will contain an automatically generated sequence number in records sent to an input stream or input window.
AUTOGENERATE (column[, ...])[FROM {long_const|parameter}]
column | Specify the name of the column in which the automatically generated value should be placed. The column must be of datatype long. |
FROM | Overrides the default starting value of zero with the specified numeric constant or value found in the specified parameter at run time. |
This clause can be used when specifying an input stream or input window in a project. It cannot be used when specifying an input stream or input window in a module. When input records do not have a natural primary key, this clause provides a way to specify a column that can be used as the primary key.
You can specify more than one column that will have its value automatically generated. The column names must be unique. At run time all of the specified columns will get the same automatically generated value.
The automatically generated columns must be of type long. When the value exceeds the maximum positive value that the long datatype can hold, the value restarts from the maximum negative value that a long datatype can hold.
By default, the values start at zero and increase by one for each insert record. This can be overridden using the FROM clause to explicitly set a starting value, specified as either a parameter or a long_const.
An input window with an auto generated column may be assigned to a log store; in which case, on a restart, the next insert will get the highest sequence number recovered from the log store plus one as the value in the automatically generated column. When there is data in the log store, the FROM clause is ignored on restart.
CREATE INPUT STREAM Trades SCHEMA (TradeId long, Symbol string, Shares integer, Price money(4)) AUTOGENERATE (TradeId);
CREATE INPUT WINDOW Trades SCHEMA (TradeId long, Symbol string, Shares integer, Price money(4)) PRIMARY KEY (TradeId) AUTOGENERATE (TradeId);