SLEEP
statementThe SLEEP
statement is used to introduce a delay or pause in the execution of a query or a batch of queries for a specific amount of time.
SurrealQL SyntaxSLEEP @duration;
The following query shows example usage of this statement.
-- Sleep one second SLEEP 1s; -- Sleep 100 milliseconds SLEEP 100ms;
For more dynamic usage of sleep, see SurrealDB’s sleep function.
A SLEEP
statement does not interfere with operations that are underway in the background, such as a DEFINE INDEX
statement using the CONCURRENTLY
clause.
CREATE |user:50000| SET name = id.id() RETURN NONE; DEFINE INDEX unique_name ON TABLE user FIELDS name UNIQUE CONCURRENTLY; INFO FOR INDEX unique_name ON TABLE user; SLEEP 50ms; INFO FOR INDEX unique_name ON TABLE user; SLEEP 50ms; INFO FOR INDEX unique_name ON TABLE user; SLEEP 50ms; INFO FOR INDEX unique_name ON TABLE user;
Possible output-------- Query 1 -------- { building: { count: 0, status: 'initial' } } -------- Query 2 -------- { building: { count: 17250, status: 'initial' } } -------- Query 3 -------- { building: { count: 33542, status: 'initial' } } -------- Query 4 -------- { building: { status: 'built' } }
SLEEP
can be useful in a small number of situations, such as: