Building a Data Stack Live with AI AgentsLivestream August 18

Skip to main content

MD_UPDATE_DIVE_CONTENT

Publishes a new version of an existing Dive. Every call creates a fresh version with the supplied content and increments the Dive's current_version; earlier versions remain readable through MD_GET_DIVE_VERSION.

To change the Dive's title or description without creating a new version, use MD_UPDATE_DIVE_METADATA instead.

Syntax

SELECT * FROM MD_UPDATE_DIVE_CONTENT(
id := '<dive_id>',
content := '<updated_jsx_source>',
description := 'What changed in this version',
required_resources := [{'url': 'md:my_db', 'alias': 'my_db'}]
);

Function arguments accept literals and getvariable() calls. Subqueries and lateral column references are rejected, so store dynamic values with SET VARIABLE first.

Parameters

ParameterTypeRequiredDescription
idUUIDYesIdentifier of the Dive to update.
contentVARCHARYesNew JSX/React source for the Dive.
descriptionVARCHARNoDescription attached to this version (separate from the Dive's own description). Useful as a change note.
required_resourcesLIST(STRUCT(url VARCHAR, alias VARCHAR))NoDatabases and shares the new content queries. Replaces the previous version's list; resources are not carried forward, so pass the full list each time.
api_versionUINTEGERNoDive API version of the content. Defaults to 1.

Return columns

Returns the newly created version:

ColumnTypeDescription
idUUIDIdentifier of the new version (not the Dive).
versionUINTEGERThe new version number.
storage_urlVARCHARInternal storage location of the version's content.
descriptionVARCHARThe version description, or NULL.
created_atTIMESTAMP WITH TIME ZONEWhen the version was created.
api_versionUINTEGERDive API version of the content.
required_resourcesLIST(STRUCT(name VARCHAR, alias VARCHAR, url VARCHAR, id UUID, resource_type VARCHAR))The resolved resources for this version.

Examples

Publish a new version with a change note:

SELECT version, created_at
FROM MD_UPDATE_DIVE_CONTENT(
id := '<dive_id>',
content := $$
import { useSQLQuery } from "@motherduck/react-sql-query";

export default function Dive() {
const { data } = useSQLQuery(`SELECT COUNT(*) AS n FROM analytics.main.orders`);
return <div>Orders: {data?.[0]?.n}</div>;
}
$$,
description := 'Switch from daily breakdown to a single total',
required_resources := [{'url': 'md:analytics', 'alias': 'analytics'}]
);