UPDATEtable_identifier
USING {stream_identifier
|stream_expression
} SETcolumn_identifier=tuple_scalar_expression
[, ...] WHEREpredicate
[RETURNINGtarget_list
] [ERROR INTOstream_identifier
];
table_identifier
-
The unique identifier (name) of the table in which to update values.
stream_identifier
-
The unique identifier (name) of the stream whose tuples contain the values that will be used to update the table.
stream_expression
-
A StreamSQL statement that produces a stream. The statement must be enclosed within parentheses.
column_identifier
-
The unique identifier (name) of a column into which a value will be replaced.
tuple_scalar_expression
-
An expression that generates a value that will be used to update the table.
predicate
-
The logic used to select specific table content.
target_list
-
One or more entries, separated by commas, of the format target_list_entry.
target_list_entry
-
A value, of the format scalar_expression [AS output_field_identifier], to be included in the result set returned by the statement.
scalar_expression
-
An expression that generates a value for the tuple that is returned by the update operation. Values can be obtained from a tuple field, a StreamBase function, or from a simple function. Optionally, the name for a value can be modified through an AS clause.
You can append an ERROR INTO clause just before the closing semicolon. The StreamSQL ERROR INTO clause is analogous to the Enable Error Output Port check box for operators and adapters in EventFlow applications.
Use ERROR INTO with the name of a stream, which must already exist. This sets up an Error Port for this operator, which is much like a local catch mechanism for errors from this operator.
See Using Error Ports and Error Streams for a discussion of StreamBase error handling mechanisms.
The UPDATE statement changes the values stored in a row of an existing table.
With the UPDATE statement, the USING clause identifies the stream whose tuples contain the values that will be used to update the table. The SET clause lists the table fields that will be modified and, for each, an expression that is the source of the new value. This expression can simply be the name of a tuple field or a value derived by applying expression operators and/or StreamBase simple functions to the values currently in the table or in the tuple.
In the RETURNING clause, scalar_expression
can specify a value from stream_expression
and/or from the table.
The result set generated by the RETURNING clause must be captured into a stream. You can use the CREATE STREAM Statement statement to define a stream and the INTO keyword to populate the stream with the content generated by the RETURNING clause. As an alternative, in a single statement use the => (arrow) operator with a CREATE STREAM statement, as illustrated below.
CREATE STREAMstream_identifier
; UPDATE ... RETURNING ... INTOstream_identifier
;
Or
UPDATE ... RETURNING ... => CREATE STREAM stream_identifier