PG_SLEEP

Pause the current session for a given number of seconds.

Category: miscReturns: VOIDDialect: PostgreSql

Syntax

PG_SLEEP(seconds)

Description

## Overview Pauses the current session for the specified number of seconds. Use this function for testing, reproducing race conditions, or pacing a script during development. It has no meaningful use in production analytics queries. ## Behavior - Accepts fractional seconds for sub-second precision. - Returns void (no meaningful value). - Deterministic with respect to the input duration but blocks the session for that duration. - Has a side effect: the session is occupied for the requested time. ## Compatibility - PG-compat alias for `pg_sleep` function.

Parameters

NameTypeDescription
secondsSpecifies the delay in seconds. Fractional values (for example, 0.5 for 500 milliseconds) are supported. Must be non-negative.

Examples

-- Sleep for one second
SELECT PG_SLEEP(1);
-- Sleep for half a second
SELECT PG_SLEEP(0.5);
-- Use during test scenarios to simulate latency
SELECT 'step 1' AS status;
SELECT PG_SLEEP(2);
SELECT 'step 2' AS status;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →