Zum Hauptinhalt springen

Run Query

POST 

/v1/query

Run an inline alias-only SQL query across the caller's own datasets.

  • datasetIds (plural, OPTIONAL):

    • Provided: each id resolves to that dataset's alias; the SQL joins the aliases. Deny-don't-drop — if the key is not authorized for EVERY id, the whole query is rejected (403 query_dataset_forbidden), never executed against the granted subset.
    • Omitted: the server INFERS the set from the aliases the SQL references (each resolved to a dataset by clean_sql_name for the calling account), then applies the SAME authorization. An alias that matches no dataset in the account → 400 query_dataset_unresolved. An inferred dataset the key isn't granted is still rejected (403) — inference is a DX convenience, NOT an authorization relaxation.
  • Dataset readiness: only a READY dataset has an Iceberg table behind it. A participating dataset still ingesting (PENDING/DOWNLOADING/ PROCESSING) → 400 query_dataset_not_ready; one whose ingestion failed (FAILED) → 400 query_dataset_failed. Both name the dataset and its processingStatus, in both backend and wasm modes.

  • sql: inline, alias-only. Physical tables / DDL / file+remote readers are rejected by the embed SQL validator (403 embed_sql_invalid).

  • params: optional pass-through column filters, bound as escaped literals (never string-interpolated). A filter on a phantom column fails closed (403 embed_filter_invalid).

  • type (Phase 208): backend (default) or wasm.

    • wasm asks for a PLAN instead of rows: the rewritten SQL plus one presigned Parquet extract per participating dataset, which the caller runs locally in DuckDB-WASM. Authorization, alias-only validation and filter injection ALL still happen server-side, in that order, BEFORE the capability check — asking for wasm cannot skip a single gate.
    • If any participating dataset is not wasm-capable (no Iceberg snapshot, or an extract over WASM_EXTRACT_MAX_BYTES), the query executes server-side exactly as today and the response reports mode: "backend" with a fallbackReason. Never a silent downgrade.
  • Live datasets (served from their connection, no copy): when every dataset named is live, the query runs on the customer's own database and the response says mode: "live", with asOf (when the statement was sent) and cached (whether this answer came from the result cache).

    • dialect absent: the same DuckDB SQL over aliases as everywhere else, translated to the source's dialect. DuckDB-only constructs the source cannot express are refused at planning time, naming the node.
    • dialect set (postgres): the source database's own SQL, written against its tables — still parsed, read-only validated and capped, never forwarded as a string. Native SQL binds no alias, so params cannot filter it, and it reaches whatever the connection's database role can read: Creator/Admin only, on a connection the caller may use; anyone else gets 404 connection_not_found. datasetIds is required (there is no alias to infer from).
    • maxAge is the oldest cached answer accepted, in seconds, never more than the smallest cacheTtlSeconds among the datasets; 0 runs on the source now and refreshes the cache.
    • datasetIds may hold live and copied datasets together: each statement runs on the lane of the datasets its SQL names. One statement cannot read a live and a copied dataset together (400 live_and_copied_datasets_cannot_mix), every live dataset must run on one connection, and type: "wasm" falls back to the live run with a fallbackReason — the browser lane cannot reach a database.
    • The lane is rolled out per account: 409 live_query_disabled while it is not open to yours. A source that times out, refuses the statement or returns more than 64 MB answers 400 live_query_failed with the source's own (sanitized) sentence.
  • Lane policy: an account declares which server lanes it pays for. A copied dataset spends extract, a live one live; an account without that lane gets 403 QUERY_LANE_NOT_PERMITTED (body carries allowedQueryLanes and laneRequired) before any row is read. A wasm plan runs in the caller's browser and spends nothing.

Returns typed columnar { columns:[{name,type}], rows } — or, in wasm mode, { mode:"wasm", plan:{ sql, sources } }. mode always states what the query ACTUALLY ran as; durationMs is the server time the answer took. Metered through the existing usage/credits mechanism in every lane. Result transport (inline vs presigned object-storage blob) is an internal decision hidden by the SDK's query().

Request​

Responses​

Successful Response