> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for READ_SNAPSHOT function

# READ_SNAPSHOT

<span className="feature-tag">Nightly Feature</span>

<Warning>
  This feature is currently in private preview. Contact [support@firebolt.io](mailto:support@firebolt.io) to request early access.
</Warning>

A table-valued function (TVF) that reads the current contents of the Postgres table or MongoDB collection behind a [change data capture stream](/guides/change-data-capture), as the initial load before its change feed. It returns the stream's declared columns and no pseudo-columns. A [CDC table](/reference-sql/commands/data-definition/create-cdc-table) runs this load itself; call it directly for a custom pipeline.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
READ_SNAPSHOT (
    STREAM <stream_name>
    [, num_reader_threads => <threads>]
    [, pages_per_task => <pages>]
)
```

## Parameters

| Parameter | Description | Supported input types |
| :- | :- | :- |
| `STREAM` | A stream over a Postgres or MongoDB location. | Stream reference |
| `num_reader_threads` | Postgres streams only. Parallel `COPY` readers, each holding one connection to the source for the whole scan. Default `8`, at most `64`. | `INT`, `BIGINT` |
| `pages_per_task` | Postgres streams only. Heap pages one reader task copies. Default `1000`. | `INT`, `BIGINT` |

`READ_SNAPSHOT` records the load in the stream's position of record, in the transaction of the statement that runs it, so it has to run inside a writing statement such as `INSERT INTO ... SELECT`. A stream attached to a CDC table cannot be loaded this way, since the table owns the stream. A statement reads a MongoDB stream at most once, counting `READ_STREAM` and `READ_SNAPSHOT` together and a `WITH` query once per reference, because each read stores the stream's whole position. A view cannot read a MongoDB stream.

## How the load lines up with the change feed

* **Postgres**: the scan reads a snapshot taken from a temporary replication slot and moves the stream's position to that snapshot. `READ_STREAM` afterwards returns exactly the transactions the snapshot does not contain.
* **MongoDB**: the load moves the stream's position to where the change feed was just before the scan. The scan is not a point-in-time read, but applying the change feed after the load converges anyway, because every change carries the whole document. Changes made during the scan can appear both in the load and in the feed. Since the load needs no stored position, it also rebuilds a stream whose position has aged out of the oplog.

## Example

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
INSERT INTO orders_load SELECT * FROM READ_SNAPSHOT(STREAM orders_changes);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.