For the conceptual overview of DQL, see Structured queries (DQL). For the column schema of each table, see DQL schema reference.
Execute a Query
Parameters
ID of the collection to query.
The DQL query string.
Optional reading plan ID for
$alias substitution in queries that reference reading step aliases.Analytics source for the execution path. Defaults to
"endpoint"; the MCP server sets "mcp" automatically. You typically do not need to set this.When
True, the server refuses the optimized parquet path unless the parquet replica reflects every committed mutation, and runs the query against Postgres otherwise. Use this when you cannot tolerate parquet lag — for example, immediately after adding or deleting agent runs, or when verifying a write.Returns
Query result.
Errors
ValueError—dqlis emptyHTTPError— Invalid DQL syntax or collection not found
Convert Results to Dicts
Parameters
A result dict returned by
execute_dql.Returns
List of dictionaries, one per row, with column names as keys.
Common Query Patterns
Filter by metadata
Join with evaluation results
Count and aggregate
Allowed syntax
DQL supported keywords:| Feature | |
|---|---|
SELECT, DISTINCT, FROM, WHERE, subqueries | |
JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN | |
WITH (CTEs) | |
UNION [ALL], INTERSECT, EXCEPT | |
GROUP BY, HAVING | |
Aggregations (COUNT, AVG, MIN, MAX, SUM, STDDEV_POP, STDDEV_SAMP, ARRAY_AGG, STRING_AGG, JSON_AGG, JSONB_AGG, JSON_OBJECT_AGG, PERCENTILE_CONT, PERCENTILE_DISC (WITHIN GROUP)) | |
Window functions (ROW_NUMBER, RANK, DENSE_RANK, NTILE, LAG, LEAD, FIRST_VALUE, LAST_VALUE, NTH_VALUE, PERCENT_RANK, CUME_DIST) | |
ORDER BY, LIMIT, OFFSET | |
Conditional & null helpers (CASE, COALESCE, NULLIF) | |
Boolean logic (AND, OR, NOT) | |
Comparison operators (=, !=, <, <=, >, >=, IS, IS NOT, IS DISTINCT FROM, IN, BETWEEN, LIKE, ILIKE, EXISTS, SIMILAR TO, ~, ~*, !~, !~*) | |
Arithmetic & math (+, -, *, /, %, POWER, ABS, SIGN, SQRT, LN, LOG, EXP, GREATEST, LEAST, FLOOR, CEIL, ROUND, RANDOM) | |
String helpers (SUBSTRING, LEFT, RIGHT, LENGTH, UPPER, LOWER, INITCAP, TRIM, REPLACE, SPLIT_PART, POSITION, CONCAT, CONCAT_WS, STRING_AGG) | |
JSON operators & functions (->, ->>, #>, #>>, @>, ?, `? | , ?&, jsonb_array_length, json_agg, jsonb_agg, json_object_agg, convert_from, convert_to`) |
Date/time basics (CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, NOW(), EXTRACT, DATE_TRUNC, AT TIME ZONE) | |
Interval arithmetic (timestamp +/- INTERVAL, INTERVAL literals) | |
Construction & conversion (MAKE_DATE, MAKE_TIME, MAKE_TIMESTAMP, TO_CHAR) | |
Array helpers (array_cat, unnest) | |
Type helpers (CAST, ::) |
* in SELECT clauses (e.g., SELECT *, COUNT(*)), user-defined functions, and any DDL or DML commands.
SQL patterns
Bare DQL snippets for common tasks.Filter by metadata field
Filter by date range
Count by category
Check if a metadata field exists
Numeric comparison on a JSON field
Cast JSON for aggregation
Counting transcript messages
transcripts.messages is stored as bytea (UTF-8 JSON), not jsonb. Operators like messages -> 0 or jsonb_array_length(messages) raise operator does not exist: bytea -> integer. Decode to jsonb first, then count array elements:
transcripts.metadata_json — decode with convert_from(metadata_json, 'UTF8')::jsonb before using JSON operators.
Agent runs with at least N messages in any transcript:
transcripts.metadata_json fields:
Join transcripts with agent runs
Transcript counts per group
Transcript coverage audit
Finds transcript groups that are marked asmust_have but have no associated transcripts.
Flagged judge results
Common gotchas
”column X does not exist”
- DQL requires explicit column selection. Wildcards (
*) are not supported. - Check the schema using
client.get_dql_schema(collection_id)to see available columns.
Numeric comparisons not working as expected
JSON fields are strings by default. Cast them for numeric operations:Query returns no results but data exists
- Check that you’re querying the correct collection
- Verify metadata field names are exact matches (case-sensitive)
- Use
?operator to check if a field exists before filtering on it
Results truncated unexpectedly
DQL caps results at 10,000 rows. UseLIMIT and OFFSET for pagination:
“syntax error” on valid-looking SQL
Some SQL features aren’t supported in DQL:- No
*wildcard in SELECT - No
INSERT,UPDATE,DELETE - No user-defined functions

