Skip to main content
Version: 1.1.0

LIVE SELECT

LIVE SELECT statement

The LIVE SELECT statement can be used to initiate a real-time selection from a table, including the option to apply filters.

In practical terms, when you execute a LIVE SELECT query, it triggers an ongoing session that captures any subsequent changes to the data in real-time. These changes are then immediately transmitted to the client, ensuring that the client is consistently updated with the latest data modifications.

Statement syntax

SurrealQL Syntax
LIVE SELECT
[
[ VALUE ] @fields [ AS @alias ]
| DIFF
]
FROM @targets
[ WHERE @conditions ]
[ FETCH @fields ... ]
;

Example usage

Basic usage

By default, SurrealDB will push the entire record over the websocket when created or updated, and just the record's ID when deleted.

LIVE SELECT * FROM person;

Diff

When using the DIFF mode, updates will be sent in the form of an array with JSON Patch messages.

LIVE SELECT DIFF FROM person;

Filter the live query

You can optionally apply filters with the WHERE clause.

LIVE SELECT * FROM person WHERE age > 18;