Skip to content

Behavior and limits

Values and reductions

On empty input, a scalar aggregate returns one row and a grouped aggregate returns no groups. Sum, average, minimum and maximum ignore nulls and return null when there are no non-null values. count() counts non-null values, including false. count_rows() counts every selected row. Both counts return zero on empty input.

Variance and standard deviation ignore nulls and return nullable Float64. Sample functions (variance() or var_samp(), stddev() or stddev_samp()) need at least two values. Population functions (var_pop(), stddev_pop()) return null for no values and zero for one value, including NaN or infinity. With two or more values, any NaN or infinity gives NaN. The result is also NaN if the Float64 calculation overflows.

any_value() returns one non-null input with its original type, or null if there is none. The chosen value can vary with execution order.

Type Operations and limits
Int8, Int16, Int32, Int64 Addition, subtraction, multiplication and negation wrap at the result width. Scalar and grouped sums return Int64.
UInt8, UInt16, UInt32, UInt64 Addition, subtraction and multiplication wrap at the result width. Scalar and grouped sums return UInt64, modulo 2⁶⁴. Unsigned negation requires a cast.
Float32, Float64 Arithmetic, comparisons and reductions. NaNs compare equal to each other and sort after numbers in ascending order.
Utf8, LargeUtf8 Bytewise comparisons, sorting, grouping, string operations and regular expressions.
Binary, LargeBinary Raw bytes, including NUL. Compares in unsigned byte order. Use byte_length() to count bytes.
Timestamp Signed microseconds since 1970-01-01, timezone-naive or UTC. Comparisons and join keys require matching timezone types.
Boolean Equality, null tests and three-valued logic.
Date32, Date64 Signed days or milliseconds since 1970-01-01. Date64 comparisons use the stored milliseconds. Both support calendar parts and day arithmetic.
Decimal128 Precision 1 to 38 and scale 0 to precision. Supports exact addition, subtraction and multiplication.
Struct Ordered named fields. Extracting a field from a null struct returns null regardless of the child's stored value.
Map Ordered key-value pairs with required keys. Values can be nullable.
List, LargeList Ordered elements of one type, including nested values. List uses signed 32-bit offsets and LargeList uses signed 64-bit offsets.

A null list and an empty list are distinct. List length counts null elements. Element indices start at zero. Negative indices count from the end. An absent element returns null. Membership ignores null elements, returns false for an empty list, and returns null for a null list or a null needle in a nonempty list. Equality compares fields or elements in order. Two null children compare equal. A null value at the outermost level gives a null comparison result. Map keys and values keep entry order. Map length counts entries, including those with null values. A null map gives null for length, keys and values. An empty map has length zero and yields two empty lists. Map lookup returns null for a missing key, a null key or a null map. Arrow maps can contain duplicate keys. Quixote returns the first matching entry. DuckDB 2.0.1 rejects duplicate keys and null keys when constructing a map.

Nested types support up to 32 levels, including the entries struct in a map. Sort, join and group by a scalar key to carry nested data through a query.

LargeUtf8 and LargeBinary use signed 64-bit byte offsets. Cast between offset widths within either type. A cast to Utf8 or Binary fails if the output array would exceed 2,147,483,647 bytes.

Integer arithmetic uses the wider operand type when signedness matches. For mixed signedness it uses the smallest signed type that can hold both ranges. Combining UInt64 with a signed integer requires an explicit cast for arithmetic, conditional branches and coalesce. Integer comparisons are exact across all widths. Integer division returns Float64. Integer window sums return Decimal128(38, 0). Integer remainder (% or modulo) truncates the quotient toward zero. A zero integer divisor raises an error. A zero floating-point divisor gives NaN. Integer casts check the destination range. Cast to Utf8 for base-ten text.

Two Float32 operands produce Float32 for addition, subtraction, multiplication and division. Combining Float32 with another numeric type uses Float64. All other divisions, floating-point sums and averages return Float64. Decimal sum uses precision 38 and keeps the input scale. Decimal arithmetic raises an error if the exact result of an addition, subtraction or multiplication overflows. Use cast(type) to convert between numeric types. Reducing a decimal's scale truncates toward zero.

Arithmetic and comparisons with a null return null. Filters keep only true, non-null values. false & null is false and true | null is true. Other combinations with null return null. Boolean operations evaluate both arguments, so an error in either argument can fail the query.

if_else(condition, yes, no) selects yes for true and no for false or null. Decimal branches use a common scale and can include integer literals. A selected value that needs more than 38 digits at that scale raises an overflow error.

null_if(a, b) returns null when the operands compare equal, including two NaNs. Otherwise it returns a, including when b is null. Its operands follow the type rules for conditional branches.

coalesce(a, b, ...) returns the first non-null value per row. Supply at least two arguments. Mixing Float32 with another numeric type promotes both to Float64. Integer arguments follow arithmetic promotion, and integers mixed with floating-point arguments use Float64. Other types must match, including decimal precision and scale or timestamp timezone. The result is nullable only when every argument is nullable.

abs() accepts integers, floating-point values and Decimal128. The minimum signed integer raises an overflow error. floor() and ceil() accept the same types and leave integers unchanged. round(digits=0) accepts floating-point values and Decimal128 and rounds ties away from zero. Negative digits round to the left of the decimal point. Both floating-point types round the stored binary value. For example, the Float64 value written as 2.675 is just below the halfway point and rounds to 2.67 at two places. Decimal results retain their precision. Floor and ceil use scale zero. Round clamps the output scale to the range between zero and the input scale. A result outside the decimal precision raises an overflow error. These operations preserve nulls.

Casting a timestamp to Int64 gives its signed microsecond count. Casting that count to a naive or UTC timestamp preserves the value.

Casting Date64 to Date32 floors to the start of the day. For example, -1 millisecond becomes 1969-12-31. Casting to Timestamp preserves the milliseconds as microseconds. Casting back floors to the preceding millisecond. Both casts check the destination range.

For a Date32, Date64 or Timestamp column d, d.year() returns the Gregorian year as Int64. d.month() (1–12) and d.day() (1–31) return Int32. Timestamp columns also support hour(), minute() and second(), all returning Int32. Use date_trunc("year"), "month" or "day" on either type. Timestamps also accept "hour", "minute" and "second". Truncation returns the start of that period in the input type and timezone. An unrepresentable start raises an overflow error. For date columns, d.date_add_days(n) accepts signed Int32 or Int64 days and preserves the input type and any time within the day. A result outside the signed 32-bit day range raises an overflow error. end.date_diff_days(start) returns the signed number of days from start to end as Int64. These date operations propagate nulls.

For integer, string, binary, date and timestamp columns, is_in(values) returns null for null inputs. A missing value returns null if the list contains null, and false otherwise.

String expressions support starts_with, ends_with, and contains. like(pattern) matches the whole string. Use % for any sequence and _ for one Unicode code point. substr(start_1based, length) counts code points starting at one. These operations preserve nulls and match case exactly.

replace(old, new) replaces non-overlapping matches from left to right. An empty search string leaves the input unchanged. split_part(delimiter, part) counts fields from one, or from the end for negative positions. Zero and out-of-range positions return an empty string. An empty delimiter splits on Unicode code points. Both functions preserve nulls.

regexp_like(pattern) searches anywhere in a string. regexp_extract(pattern, group=0) returns the first match. Group 0 selects the whole match and groups 1 through 9 select captures. A missing match or capture returns "". Indices outside 0 through 9 raise an error. Both methods propagate nulls.

regexp_replace(pattern, replacement) changes the first match. Pass replace_all=True to change every non-overlapping match. In a Python raw replacement string, \0 inserts the whole match, \1 through \9 insert captures, and \\ inserts a backslash. A reference must name a group in the pattern. $1 is literal text. An empty pattern inserts at character boundaries. Global replacement skips an empty match at the end of the previous match. Extraction and replacement preserve Utf8 or LargeUtf8.

Patterns support ., ^, $, bracket classes, ASCII \d, \w, \s and their uppercase complements, groups, alternation and greedy or lazy repetition. . matches one Unicode code point except newline. Use (?s) to include newlines, (?m) for line anchors, and (?i) for Unicode simple case folding. Scope flags with (?i:...). The binder rejects lookarounds, pattern backreferences, repeat counts above 1,000 and patterns exceeding its size or nesting limits.

s.length() counts Unicode code points, including combining marks. s.byte_length() counts UTF-8 bytes. Both return Int64. lower() and upper() change ASCII letters only. For example, uppercasing "café" gives "CAFé". trim(), ltrim() and rtrim() remove Unicode space separators (category Zs) from both ends, the start or the end, respectively. Tabs and line breaks are preserved. s.concat(t) joins two strings and returns null if either input is null. All unary string operations return null for a null input.

Group keys may be integers, floating-point numbers, strings, bytes, Boolean, Timestamp or dates. Null keys form their own groups. Use group_by(*keys).agg() or C++ GroupBy(keys, {}) for one row per distinct tuple. Use distinct() or C++ Distinct() to compare all columns, including decimals. Rows with nulls in the same positions compare equal when their other values match. In a group, count_distinct() (C++ CountDistinct()) ignores nulls and returns a non-nullable Int64. A group with only nulls returns zero. Group order is unspecified. Filter/project/limit preserve source order, subject to any earlier unordered grouping. Direct column aliases retain field metadata; computed expressions clear it. Schema metadata survives. Duplicate output names and mixed scalar/reduction projections are errors.

sort("key", "other", descending=[False, True]) orders rows by named columns. Equal keys keep incoming order. Nulls come last by default in either direction; use nulls_first=True to put them first. With a positive limit immediately after the sort, Quixote scans all rows but keeps only the best candidates and the batches they reference. With an offset, Quixote uses this bounded sort when the offset plus the requested rows is at most 2048. Larger offset pages use the full sort. Set a spill directory to sort inputs larger than the working budget.

Window functions

A window appends a value to each input row. All supported types can partition and order rows. Null partition keys group together. Equal order keys form a peer group, including equal nulls and NaNs. Within a tie, navigation and row numbering follow input order. Add a unique order key when that order matters. Use a final sort to choose the order of the result.

row_number(), rank() and dense_rank() start at one in each partition. Peers share a rank. After a tie, rank skips the occupied positions and dense rank advances by one. With no order keys, all rows in a partition are peers. lag() and lead() look back or ahead by a nonnegative row count. Zero selects the current row. The default applies only outside the partition. An in-range null stays null.

With order keys, sum, count, average and extrema include every row through the last peer of the current row. Without order keys they cover the entire partition. Integer window sums use Decimal128(38, 0). Windows consume their input before emitting batches of up to 4,096 rows. The sort, retained input and window state must fit the query budget.

Appending queries

Use left.union_all(right), C++ left.UnionAll(right), or qe.union_all(queries) for a nonempty iterable. Rows arrive in input order, including duplicates. All inputs must belong to the same session. Fields match by position and must have identical types, including decimal precision, scale, and timestamp timezone. The first input supplies field names and metadata. A field is nullable if any input allows nulls there.

Independent inputs stream in sequence. When branches read the same one-shot source, they share one cursor on the source. The query budget must cover the batches that later branches still need to read.

Intersecting and subtracting queries

left.intersect(right) returns each row that occurs in both inputs once. left.except_(right) returns each row that occurs only in the left input once. Pass all=True to count copies. For a row that appears five times on the left and twice on the right, intersection returns two copies and subtraction returns three.

Both operations use the same session and positional schema rules as union_all. They keep the left field names, field metadata and schema metadata. A field is nullable if either input allows nulls. Equality compares every column. Nulls match nulls, NaNs match NaNs, and signed zeros match. Text and binary values compare byte for byte. With zero columns, all rows compare equal.

Quixote counts both inputs before emitting results. Set a spill directory for counts larger than the working memory limit. Stream large results and use sort() when row order matters.

Joining queries

Both inputs must come from the same session. Use left.join(right, on="id") for shared key names, or pass left_on and right_on for different names. For composite keys, list the columns in matching order. All supported query types can serve as join keys. Corresponding types must agree. A null in any key prevents a match.

For Float32 and Float64 keys, positive and negative zero match, and NaNs match each other. The default inner join returns every matching pair. A left join also returns each unmatched left row. Use how="right" for matching pairs and each unmatched right row, or how="full" to keep unmatched rows from both inputs. All four joins retain both sets of columns. On an unmatched row, every column from the missing side is null, including its join keys. Right fields that share a left name get suffix (default "_right"). The resulting names must be unique. A cross join takes no keys and considers every pair. The join build state must fit in the query budget.

Use how="semi" to keep left rows with a match or how="anti" to keep those without one. The optional filter expression sees fields from both inputs, including suffixed names. Only pairs where it evaluates to true count as matches. Semi and anti joins return the original left columns.

Execution and lifetimes

Queries are immutable. In-memory array inputs and unchanged local Parquet scans are repeatable; an imported Arrow stream has one admitted execution. Failed admission does not consume that stream. After execution starts, failure or cancellation does not make it reusable.

limit(rows, offset=0) skips the first offset rows and returns up to rows in input order. An offset at or beyond the end returns an empty result. limit(0) validates the plan/schema without pulling input. Other limits stop upstream work after the required rows, then drain already accepted work. Errors from accepted work still propagate. Foreign stream callbacks and blocking file I/O cannot be forcibly interrupted and can delay cancellation/close.

Results, exported Arrow objects and delivered batches remain valid after closing their stream, session or runtime. Keep borrowed input storage immutable until released. A Result has repeatable batch cursors/exports; a Stream is one single-consumer cursor, so choose iteration or an Arrow consumer for that cursor.

The first execution failure is preserved; unpublished output is discarded and accepted work drains. Already delivered batches remain valid. Session.cancel() affects active queries in that session; closing the session rejects new work. Closing a runtime drains its sessions and executors. Close is idempotent.

Memory budgets

Each query has a working memory budget. It covers execution state, temporary buffers and results that have not been handed to the caller.

  • collect() keeps the whole result inside this budget until completion.
  • stream() hands over one batch at a time. Once delivered, a batch belongs to the caller. Keeping earlier batches does not block the next pull.
  • A slice keeps its entire backing allocation alive; two views of the same allocation count it once.

The runtime's memory_limit controls which queries can start. Most queries reserve their full working budget. A scalar aggregate over a Parquet scan can reserve less. A request fails immediately if its budget exceeds the runtime limit, or if results you still hold leave too little space. Release those results and retry. If active queries are the blocker, it may wait. Smaller fitting queries can pass a larger waiting query.

An admitted stream keeps progressing even if the results you hold grow beyond the runtime limit. Process memory can exceed the runtime limit. Imported Arrow data, some metadata, adapter/codec allocations and allocator overhead are outside the working budget. A large page, dictionary or group table can exhaust the budget even when streaming.

runtime.stats() / C++ MemoryStats expose active_reserved_bytes, working_live_bytes, held_bytes, imported_logical_bytes and metadata_logical_bytes. Logical imported/metadata totals are not RSS or unique physical bytes. The lifetime peaks for working, reserved and held memory are peak_working_bytes, peak_reserved_bytes and peak_held_bytes. These maxima can occur at different times.

Errors

Python budget errors use ResourceLimitError(MemoryError); actual allocation failure can also raise MemoryError. Cancellation uses CancelledError and Ctrl-C uses KeyboardInterrupt. Other binding/type/I/O/unsupported failures map to ordinary Python exceptions. C++ uses exported EngineError with an ErrorCode. Arrow C callbacks never propagate C++ exceptions: check status/error text and release all exported objects.

Common problems

Problem Next step
Import has no Runtime or Session Check quixote.__file__ in the interpreter you run. Use an isolated environment with quixote-engine; the unrelated quixote distribution shares the import name.
A query exceeds its budget Use streaming for a large output, or increase the query budget and runtime limit together. Streaming still needs enough working memory for pages and group tables.
A second query cannot start while you hold results Release unneeded results and retry. Raising the runtime limit allows more admission space.
An imported stream cannot run a second time Import the producer again. A PyArrow RecordBatch input is repeatable; an imported Table uses its one-shot stream interface.
A Parquet field is unsupported Pass columns=[...] with the top-level fields you need. Every leaf in a selected field must have a supported type.
Output already exists Choose another path or explicitly pass overwrite=True. Failed writes preserve the existing destination.

Disk spilling

Sorts, grouped aggregates, intersections and differences can use temporary files when the runtime has a spill directory. An empty directory setting disables spilling. A zero spill byte limit allows unlimited disk use. The working memory limit still applies to input, each merge, and collected output. Stream results to consume an output larger than the query budget.

Runtime statistics report live disk use (spilled_bytes), its lifetime peak (peak_spilled_bytes), and all bytes written including intermediate merges (total_spilled_bytes). Closing or cancelling the query releases its files.