SingleStore Managed Service

SLEEP

Halts execution of the thread for the given number of seconds.

Syntax
SLEEP ( seconds )
Arguments
  • seconds: the number of seconds (or fraction) to sleep the thread.

Return type

Returns an integer. Specifically, SLEEP() returns the number 0 if it returns normally without interruption. If the query that is being halted is killed or times out, SLEEP() returns the number 1.

Examples

This function is useful mainly for debugging and measurement purposes, e.g., to make sure a list of queries runs at certain intervals.

SELECT NOW(); SELECT SLEEP(10); SELECT NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2015-03-02 23:22:25 |
+---------------------+

+-----------+
| SLEEP(10) |
+-----------+
|         0 |
+-----------+

+---------------------+
| NOW()               |
+---------------------+
| 2015-03-02 23:22:35 |
+---------------------+

You can also specify fractions of a second:

SELECT NOW(6); SELECT SLEEP(0.25); SELECT NOW(6);

+----------------------------+
| NOW(6)                     |
+----------------------------+
| 2021-07-28 18:09:08.596529 |
+----------------------------+

1 row in set (0.01 sec)

+-------------+
| SLEEP(0.25) |
+-------------+
|           0 |
+-------------+

1 row in set (0.26 sec)

+----------------------------+
| NOW(6)                     |
+----------------------------+
| 2021-07-28 18:09:08.850666 |
+----------------------------+

1 row in set (0.00 sec)