# MD_UPDATE_FLIGHT
> Update a Flight's source code, requirements, config, token, secrets, run timeout, instance size, chart, name, or schedule.
Updates an existing [Flight](/concepts/compute/flights). Behaves as a PATCH: only the parameters you pass are modified, and unspecified fields are left unchanged.

Updates to `source_code`, `requirements_txt`, `config`, `access_token_name`, `flight_secret_names`, `max_runtime_sec`, `instance_type`, or the chart in `metadata` produce a fresh `FlightVersion`. Updates to `name` or `schedule_cron` are metadata-only and do not bump the version.

You are responsible for the code you run and the packages it installs. Flights does not scan customer code or dependencies. Avoid untrusted packages, pin dependency versions, and treat dependency installs as a supply-chain risk.

## Syntax

```sql
CALL MD_UPDATE_FLIGHT(
    flight_id := '<flight_id>',
    name := '<updated_name>',
    schedule_cron := '0 0 * * *',
    source_code := '<updated_python>',
    requirements_txt := '<updated_requirements>',
    config := MAP {'KEY': 'value'},
    access_token_name := '<updated_token_name>',
    flight_secret_names := ['secret_name'],
    max_runtime_sec := 3600,
    instance_type := 'F16',
    metadata := MAP {'chart': '<mermaid_flowchart>'}
);
```

## Parameters

| Parameter | Type | Required | Description |
|---|---|---|---|
| `flight_id` | `UUID` | Yes | Identifier of the Flight to update. |
| `name` | `VARCHAR` | No | New Flight name. Must be non-empty when provided. Metadata-only. |
| `schedule_cron` | `VARCHAR` | No | New cron expression (UTC, 5 fields). Pass `''` (empty string) to clear the schedule. Metadata-only. |
| `source_code` | `VARCHAR` | No | New Python source. Bumps the version. |
| `requirements_txt` | `VARCHAR` | No | New `requirements.txt` contents. Bumps the version. |
| `config` | `MAP(VARCHAR, VARCHAR)` | No | Replacement config map (full replace, not merge). Bumps the version. |
| `access_token_name` | `VARCHAR` | No | New access token label. Bumps the version. |
| `flight_secret_names` | `VARCHAR[]` | No | Replacement list of [Flight secret](/sql-reference/motherduck-sql-reference/create-secret#flight-secrets) names (full replace). Bumps the version. |
| `max_runtime_sec` | `UINTEGER` | No | Per-run timeout in seconds. `0` means no timeout. Omit to use your plan's default. A value above your plan's cap is rejected. Bumps the version. |
| `instance_type` | `VARCHAR` | No | New [instance size](/about-motherduck/billing/flight-sizes/): `'F4'`, `'F16'`, or `'F32'`. A size your plan doesn't offer is rejected. Bumps the version, even when the size is unchanged. |
| `metadata` | `MAP(VARCHAR, VARCHAR)` | No | Flight control metadata. The only supported key is `chart`: the Flight's run chart for the [Flight Explainer](/key-tasks/flights/observability/explain-flight-runs), as raw Mermaid starting at the `flowchart` line. Limited to 64 KiB as UTF-8. Bumps the version when the chart changes. See [chart behavior](#behavior). |

At least one of the above (besides `flight_id`) must be set.

## Return columns

`MD_UPDATE_FLIGHT` returns the updated `FlightSummary`:

| Column | Type | Description |
|---|---|---|
| `flight_id` | `UUID` | The Flight identifier. |
| `flight_name` | `VARCHAR` | The current name. |
| `schedule_cron` | `VARCHAR` | The current cron expression, or `NULL`. |
| `schedule_status` | `VARCHAR` | Schedule state (for example, `SCHEDULE_STATUS_ACTIVE` or `SCHEDULE_STATUS_DISABLED`), or `NULL` when the Flight has no schedule. |
| `status` | `VARCHAR` | Flight status (for example, `JOB_STATUS_ACTIVE`). Not the schedule state — see `schedule_status`. |
| `current_version` | `UINTEGER` | The current version (incremented for content updates). |
| `created_at` | `TIMESTAMP WITH TIME ZONE` | Original creation timestamp. |
| `updated_at` | `TIMESTAMP WITH TIME ZONE` | Most recent update timestamp. |
| `owner_name` | `VARCHAR` | The user who owns the Flight. |

## Behavior

- **Full-replace semantics.** `config` and `flight_secret_names` are replaced, not merged. To change one entry, send the full updated map or list.
- **Carry-forward semantics.** When you patch one content field, the resulting version carries unchanged content fields forward from the previous version.
- **Empty schedule.** `schedule_cron := ''` clears the schedule; omit it to leave the existing schedule untouched. Passing `schedule_cron := ''` to a Flight that already has no schedule returns an error, so only send it when there's a schedule to clear.
- **Chart updates.** `metadata := MAP {'chart': '<mermaid>'}` sets the chart and creates a version. Sending the chart the Flight already has is a no-op. `MAP {'chart': ''}` clears the chart and creates a version. `MAP {'chart': NULL}` leaves the chart unchanged, and on its own fails because no parameter was provided. Any key other than `chart` fails with `Parameter "metadata" only supports the key "chart"`.
- **Definition size limit.** `source_code` is capped at 200 KB and `requirements_txt` at 20 KB. Load large reference data from object storage at run time instead of embedding it in the source.
- **Resizing redeploys.** The instance size is part of the deployed version, so changing `instance_type` creates a version and redeploys the Flight. Each run executes on the size its version recorded.
- **Resizing isn't idempotent.** Passing the size the Flight already has still creates a version and redeploys. If you reconcile sizes from a script, compare against the latest `instance_type` from [`MD_LIST_FLIGHT_VERSIONS`](../md-list-flight-versions) first and only call `MD_UPDATE_FLIGHT` when it differs.
- **Plan-restricted sizes.** Only `F4`, `F16`, and `F32` are accepted, and only the sizes your plan offers. A size your plan doesn't offer fails with an error that lists the ones it does, for example:

  ```text
  Invalid Input Error: instance_type F32 is not available on your plan. Choose one of: F4, F16.
  ```

## Examples

Rename a Flight (metadata-only, no new version):

```sql
CALL MD_UPDATE_FLIGHT(
    flight_id := '<flight_id>',
    name := 'analytics_hourly_sync'
);
```

Update the source (bumps the version):

```sql
CALL MD_UPDATE_FLIGHT(
    flight_id := '<flight_id>',
    source_code := $$
def main():
    print("v2")

if __name__ == "__main__":
    main()
$$
);
```

Move a Flight to a larger instance size (bumps the version and redeploys):

```sql
CALL MD_UPDATE_FLIGHT(
    flight_id := '<flight_id>',
    instance_type := 'F32'
);
```

Add or replace the Flight's chart for the [Flight Explainer](/key-tasks/flights/observability/explain-flight-runs) (bumps the version):

```sql
CALL MD_UPDATE_FLIGHT(
    flight_id := '<flight_id>',
    metadata := MAP {'chart': 'flowchart TD
  extract[Pull orders from API]:::extract --> load[Write to warehouse]:::load
  load --> verify{Row counts match?}:::check'}
);
```

Clear the chart:

```sql
CALL MD_UPDATE_FLIGHT(
    flight_id := '<flight_id>',
    metadata := MAP {'chart': ''}
);
```

Clear the schedule, leave everything else:

```sql
CALL MD_UPDATE_FLIGHT(
    flight_id := '<flight_id>',
    schedule_cron := ''
);
```

## Related

- [`MD_CREATE_FLIGHT`](../md-create-flight) — Create a Flight.
- [`MD_GET_FLIGHT`](../md-get-flight) — Inspect the current Flight summary.
- [`MD_LIST_FLIGHT_VERSIONS`](../md-list-flight-versions) — List historical versions.
- [`update_flight` MCP tool](/sql-reference/mcp/) — AI-agent equivalent (uses `access_token_name` / `flight_secret_names`).


---

## 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%2Fflights%2Fmd-update-flight%2F&page_title=MD_UPDATE_FLIGHT&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.
