# Flights functions
> SQL table functions for creating, scheduling, running, and inspecting MotherDuck Flights.
SQL table functions for managing [Flights](/concepts/flights), MotherDuck's scheduled Python execution. Use these functions from any MotherDuck client (DuckDB CLI, BI tool, or another Flight) to create, schedule, list, and monitor Flights without leaving SQL.

The MCP server exposes the same operations to AI agents through `create_flight`, `list_flights`, `run_flight`, and so on. The MCP and SQL surfaces use slightly different parameter names — see each function page for the details, or read the [Flights MCP reference](/sql-reference/mcp/) for the agent-facing tools.

:::note
These functions execute server-side on MotherDuck. They are not available on local-only DuckDB connections.
:::

A minimal end-to-end Flight from SQL:

```sql
-- Create the Flight
SELECT flight_id, current_version
FROM MD_CREATE_FLIGHT(
    name := 'heartbeat',
    access_token_name := '<your_token_name>',
    source_code := $$
import duckdb

def main():
    con = duckdb.connect("md:")
    con.execute("CREATE DATABASE IF NOT EXISTS flights_demo")
    print("ok")
$$,
    requirements_txt := 'duckdb==1.5.2'
);

-- Trigger an on-demand run
CALL MD_RUN_FLIGHT(flight_id := '<flight_id>');

-- Inspect the run
SELECT run_number, status, created_at
FROM MD_FLIGHT_RUNS(flight_id := '<flight_id>')
ORDER BY run_number DESC LIMIT 1;
```

## Available functions

## Included pages

- [MD_CREATE_FLIGHT](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-create-flight): Create a new Flight in your MotherDuck account.
- [MD_UPDATE_FLIGHT](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-update-flight): Update a Flight's source code, requirements, config, token, secrets, name, or schedule.
- [MD_DELETE_FLIGHT](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-delete-flight): Delete a Flight, its versions, runs, and logs.
- [MD_GET_FLIGHT](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-get-flight): Fetch the summary metadata for a single Flight.
- [MD_GET_FLIGHT_VERSION](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-get-flight-version): Fetch the full content (source, requirements, config, token, secrets) for a specific Flight version.
- [MD_FLIGHTS](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-flights): List the Flights you own with summary metadata.
- [MD_FLIGHT_VERSIONS](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-flight-versions): List the version history of a Flight.
- [MD_RUN_FLIGHT](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-run-flight): Trigger an on-demand execution of a Flight using its current version.
- [MD_FLIGHT_RUNS](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-flight-runs): List the execution history of a Flight, newest first.
- [MD_FLIGHT_LOGS](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-flight-logs): Read the combined stdout and stderr captured during a Flight run.
- [MD_CANCEL_FLIGHT_RUN](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/flights/md-cancel-flight-run): Cancel an in-progress Flight run.


---

## Docs feedback

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

Payload:

```json
{
  "page_path": "/sql-reference/motherduck-sql-reference/flights/",
  "page_title": "Flights functions",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

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