REPLACE Statement

Syntax

REPLACE INTO table_identifier '('column_identifier[, ...]')' stream_expression
  [RETURNING target_list]
  [ERROR INTO stream_identifier];

Substitutable Fields

table_identifier

The unique identifier (name) of the table in which to replace values.

column_identifier

The unique identifier (name) of a column into which a value will be replaced.

stream_expression

A stream expression, for example a SELECT clause against a stream, which provides the values used to modify the table.

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 replace operation. The name for a value can be modified through an AS clause.

ERROR INTO 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.

Discussion

The REPLACE statement deletes and replaces an existing row in a table.

With the REPLACE statement, the INTO clause lists the table fields that will be modified. The stream_expression is a SELECT clause against a stream whose tuples contain the data that will be entered into the table. Its target list identifies the tuple fields that will provide the content for each table field.

If the tuple fields are in an order that corresponds to the order of table fields, you can use an asterisk (*) as the target list. Otherwise the target list must explicitly extract each tuple field, as illustrated below.

SELECT * FROM stream_identifier
SELECT tuple_field_identifier[, ...] FROM stream_identifier

In the RETURNING clause, scalar_expression can specify a value from the 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 STREAM stream_identifier;
REPLACE ... RETURNING ... INTO stream_identifier;

Or

REPLACE ... RETURNING ... => CREATE STREAM stream_identifier