📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

WITH CONSUME



Consumes data from a stream within a SELECT query.

See also: WITH Stream Hints

Syntax

SELECT ... FROM <stream_name> WITH CONSUME [ AS <alias> ] [ WHERE <conditions> ]

Examples

Suppose we have a stream named 's' that has captured the following data:

SELECT * FROM s; ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │ a │ change$action │ change$row_id │ change$is_update │ ├─────────────────┼──────────────────┼────────────────────────────────────────┼──────────────────┤ │ 3INSERT4942372d864147e98188f3b486ec18d2000000 │ false │ │ 1DELETE3df95ad8552e4967a704e1c7209d3dff000000 │ false │ └────────────────────────────────────────────────────────────────────────────────────────────────┘

If we now query the stream using WITH CONSUME, we would get the following result:

SELECT a FROM s WITH CONSUME AS ss WHERE ss.change$action = 'INSERT'; ┌─────────────────┐ │ a │ ├─────────────────┤ │ 3 │ └─────────────────┘

The stream is now empty because the query above has consumed all of the data present in the stream.

-- empty results SELECT * FROM s;

Was this page helpful?