# MD_GET_DIVE_VERSION
> Fetch the content of a specific Dive version.
Returns a single version of a [Dive](/key-tasks/ai-and-motherduck/dives), including its component code. Use this to read the code that was live at an earlier point, or to restore it by passing it back to [`MD_UPDATE_DIVE_CONTENT`](../md-update-dive-content).

## Syntax

```sql
SELECT * FROM MD_GET_DIVE_VERSION(
    id := '<dive_id>',
    version := <n>
);
```

## Parameters

| Parameter | Type | Required | Description |
|---|---|---|---|
| `id` | `UUID` | Yes | Identifier of the Dive. |
| `version` | `UINTEGER` | Yes | The version to fetch. Version numbers start at `1` and increment on each content update. |

## Return columns

| Column | Type | Description |
|---|---|---|
| `id` | `UUID` | Identifier of the version (not the Dive). |
| `version` | `UINTEGER` | The version number. |
| `storage_url` | `VARCHAR` | Internal storage location of the version's content. |
| `description` | `VARCHAR` | Description attached to the version, or `NULL`. |
| `created_at` | `TIMESTAMP WITH TIME ZONE` | When the version was created. |
| `api_version` | `UINTEGER` | Dive API version of the content. |
| `required_resources` | `LIST(STRUCT(name VARCHAR, alias VARCHAR, url VARCHAR, id UUID, resource_type VARCHAR))` | Databases and shares this version queries. |
| `content` | `VARCHAR` | The JSX/React source of this version. |

## Examples

Read the first version's code:

```sql
SELECT version, content
FROM MD_GET_DIVE_VERSION(
    id := '80000000-0000-0000-0000-000000000001',
    version := 1
);
```

Roll back by republishing an older version's content. Function arguments accept literals and `getvariable()` calls, but not subqueries or lateral column references. Store the old content in a SQL variable, then pass it back with `getvariable()`:

```sql
-- Step 1: read the content to restore into a SQL variable
SET VARIABLE rollback_content = (
    SELECT content
    FROM MD_GET_DIVE_VERSION(id := '<dive_id>', version := 2)
);

-- Step 2: republish it as a new version
SELECT version
FROM MD_UPDATE_DIVE_CONTENT(
    id := '<dive_id>',
    content := getvariable('rollback_content'),
    description := 'Roll back to version 2'
);
```

## Related

- [`MD_LIST_DIVE_VERSIONS`](../md-list-dive-versions) — List all versions of a Dive.
- [`MD_GET_DIVE`](../md-get-dive) — Fetch the latest version and summary in one call.


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

URL-encode query parameter values and send a GET request:

```text
GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fsql-reference%2Fmotherduck-sql-reference%2Fdives%2Fmd-get-dive-version%2F&page_title=MD_GET_DIVE_VERSION&text=<url-encoded user feedback, max 2000 characters>
```

Optionally append `&source=<url-encoded interface identifier>` such as `claude.ai` or `chatgpt`.

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed query parameters, and `429` when rate-limited.
