MD_GET_FLIGHT_LOGS
Preview
This feature is in preview and is subject to change.
Returns the captured logs for a single Flight run, one row per line. The output combines stdout and stderr in the order the runtime captured them, and a window of lines can be selected with "LIMIT", "OFFSET", and "ORDER" instead of fetching everything.
Syntax
SELECT * FROM MD_GET_FLIGHT_LOGS(
flight_id := '<flight_id>',
run_number := <n>,
"LIMIT" := <n>,
"OFFSET" := <n>,
"ORDER" := 'asc'
);
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
flight_id | UUID | Yes | Identifier of the Flight. | |
run_number | UBIGINT | Yes | The run number to fetch logs for. | |
LIMIT | UINTEGER | No | (all lines) | Maximum number of lines to return. Must be at least 1 when set. |
OFFSET | UINTEGER | No | 0 | Skip this many lines, counted from the end ORDER reads from. Requires LIMIT. |
ORDER | VARCHAR | No | 'asc' | Which end of the log the window is taken from: 'asc' selects from the first line, 'desc' from the last (the tail). |
LIMIT, OFFSET, and ORDER are SQL keywords and must be quoted when used as named arguments.
Return columns
| Column | Type | Description |
|---|---|---|
line_number | BIGINT | Position of the line in the run's output, starting at 1, or NULL when the runtime reported none. |
reported_at | TIMESTAMP WITH TIME ZONE | When the runtime captured the line, or NULL when unreported. |
line | VARCHAR | The log line. |
Sort by line_number for a stable reading order regardless of "ORDER".
Behavior
- Returns an error when no run with the given
run_numberexists for the Flight, or when the Flight itself doesn't exist. - Available for runs in any terminal status (
SUCCEEDED,FAILED,CANCELLED) and during aRUNNINGrun. - Parameters must be literals or
getvariable()calls. Subqueries and lateral join columns fail with a binder error; store dynamic values withSET VARIABLEfirst. - Clients on DuckDB versions before 1.5.5 bind this function's previous schema instead: a single row with one
logs VARCHARcolumn holding the full combined output, without the line window parameters.
Examples
Tail the last 100 lines of a run:
SELECT line_number, line
FROM MD_GET_FLIGHT_LOGS(
flight_id := '<flight_id>',
run_number := 42,
"LIMIT" := 100,
"ORDER" := 'desc'
)
ORDER BY line_number;
Read the latest run's full logs:
SET VARIABLE latest_run_number = (
SELECT max(run_number)
FROM MD_LIST_FLIGHT_RUNS(flight_id := '<flight_id>')
);
SELECT line_number, reported_at, line
FROM MD_GET_FLIGHT_LOGS(
flight_id := '<flight_id>',
run_number := getvariable('latest_run_number')
)
ORDER BY line_number;
Find errors in a run:
SELECT line_number, line
FROM MD_GET_FLIGHT_LOGS(flight_id := '<flight_id>', run_number := 42)
WHERE line ILIKE '%error%'
ORDER BY line_number;
Related
MD_LIST_FLIGHT_RUNS— Find the run number to read logs for.MD_GET_FLIGHT_RUN— Fetch one run's status directly.MD_RUN_FLIGHT— Trigger an on-demand run.get_flight_run_logsMCP tool — AI-agent equivalent, with amax_bytescap.