> This page location: Date Functions > PG_SLEEP
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL PG_SLEEP() Function

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `PG_SLEEP()` function to pause the execution of a query.

## Introduction to the PostgreSQL PG_SLEEP() function

The `PG_SLEEP()` function allows you to create a delay (sleep) in your queries. The function can be useful when you want to test, simulate real-time processes, or add a pause between operations.

Here's the syntax of the `PG_SLEEP()` function:

```sql
PG_SLEEP(seconds)
```

In this syntax, the `seconds` parameter specifies the number of seconds for which you want the execution to pause. It can be an integer or a decimal number with fractions.

## The PostgreSQL PG_SLEEP() function examples

Let's explore some examples of using the `PG_SLEEP()` function.

### 1) Basic usage of PG_SLEEP() function

The following example uses the `PG_SLEEP()` function to pause the execution for 3 seconds before returning any result:

```sql
SELECT pg_sleep(3);
```

After 3 seconds:

```text
 pg_sleep
----------

(1 row)
```

### 2) Using Fractional Seconds

The following example uses the `PG_SLEEP()` function to pause the execution for `1.5` seconds:

```sql
SELECT PG_SLEEP(1.5);
```

After `1.5` seconds:

```text
 pg_sleep
----------

(1 row)
```

### 3) Using the PG_SLEEP() function with NOW() function

The following example uses the `PG_SLEEP()` function between the [`NOW()`](https://neon.com/postgresql/postgresql-date-functions/postgresql-now) functions:

```sql
SELECT NOW(), PG_SLEEP(3), NOW();
```

Output:

```
-[ RECORD 1 ]---------------------------
now      | 2024-03-21 02:26:37.710939-07
pg_sleep |
now      | 2024-03-21 02:26:37.710939-07
```

The output indicates that the result of the `NOW()` function does not change within the same statement even though we use pause the execution between the calls of the `NOW()` functions for 3 seconds.

### 4) Using the PG_SLEEP() function with CLOCK_TIMESTAMP() function

The following example uses the `PG_SLEEP()` function between the [`CLOCK_TIMESTAMP()`](https://neon.com/postgresql/postgresql-date-functions/postgresql-clock_timestamp) functions:

```sql
SELECT CLOCK_TIMESTAMP(), PG_SLEEP(3), CLOCK_TIMESTAMP();
```

Output:

```
-[ RECORD 1 ]---+------------------------------
clock_timestamp | 2024-03-21 02:27:03.181753-07
pg_sleep        |
clock_timestamp | 2024-03-21 02:27:06.186789-07
```

The output shows that the [`CLOCK_TIMESTAMP()`](https://neon.com/postgresql/postgresql-date-functions/postgresql-clock_timestamp) returns the actual current timestamp when it executes. The results of the `CLOCK_TIMESTAMP()` function calls are 3 seconds difference.

## Summary

- Use the `PG_SLEEP()` function to pause the SQL execution for a number of seconds.

---

## Related docs (Date Functions)

- [AGE](https://neon.com/postgresql/postgresql-date-functions/postgresql-age)
- [AT TIME ZONE Operator](https://neon.com/postgresql/postgresql-date-functions/postgresql-at-time-zone)
- [CLOCK_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-clock_timestamp)
- [CURRENT_DATE](https://neon.com/postgresql/postgresql-date-functions/postgresql-current_date)
- [CURRENT_TIME](https://neon.com/postgresql/postgresql-date-functions/postgresql-current_time)
- [CURRENT_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-current_timestamp)
- [DATE_PART](https://neon.com/postgresql/postgresql-date-functions/postgresql-date_part)
- [DATE_TRUNC](https://neon.com/postgresql/postgresql-date-functions/postgresql-date_trunc)
- [EXTRACT](https://neon.com/postgresql/postgresql-date-functions/postgresql-extract)
- [ISFINITE](https://neon.com/postgresql/postgresql-date-functions/postgresql-isfinite)
- [JUSTIFY_DAYS](https://neon.com/postgresql/postgresql-date-functions/postgresql-justify_days)
- [JUSTIFY_HOURS](https://neon.com/postgresql/postgresql-date-functions/postgresql-justify_hours)
- [JUSTIFY_INTERVAL](https://neon.com/postgresql/postgresql-date-functions/postgresql-justify_interval)
- [LOCALTIME](https://neon.com/postgresql/postgresql-date-functions/postgresql-localtime)
- [LOCALTIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-localtimestamp)
- [MAKE_DATE](https://neon.com/postgresql/postgresql-date-functions/postgresql-make_date)
- [MAKE_INTERVAL](https://neon.com/postgresql/postgresql-date-functions/postgresql-make_interval)
- [MAKE_TIME](https://neon.com/postgresql/postgresql-date-functions/postgresql-make_time)
- [NOW](https://neon.com/postgresql/postgresql-date-functions/postgresql-now)
- [STATEMENT_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-statement_timestamp)
- [TIMEOFDAY](https://neon.com/postgresql/postgresql-date-functions/postgresql-timeofday)
- [TO_DATE](https://neon.com/postgresql/postgresql-date-functions/postgresql-to_date)
- [TO_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-to_timestamp)
