PostgreSQL pg_sleep_until() Function
The PostgreSQL pg_sleep_until() function receives a timestamp value and pauses the execution of the current server process until this specified moment.
pg_sleep_until() Syntax
Here is the syntax of the PostgreSQL pg_sleep_until() function:
pg_sleep_until(sleep_to TIMESTAMP WITH TIME ZONE)
Parameters
sleep_to-
Required. It indicates when the current server process should stop sleeping.
Return value
The PostgreSQL pg_sleep_until() function has no return value and pauses the execution of the current server process to this specified time.
pg_sleep_until() Examples
This example combined clock_timestamp() demonstrates the capabilities of pg_sleep_until().
SELECT
clock_timestamp(),
pg_sleep_until('2022-05-20 11:35:50+08'),
clock_timestamp();
-[ RECORD 1 ]---+------------------------------
clock_timestamp | 2022-05-20 11:35:41.080176+08
pg_sleep_until |
clock_timestamp | 2022-05-20 11:35:50.013833+08Here, we use the pg_sleep_until() function to suspend the execution of the server process to 2022-05-20 11:35:50+08, and then the second clock_timestamp() function returns the current time.