Skip to main content

mr mrql run

Execute a saved MRQL query by name or numeric ID. The argument is tried as an ID first and then as a name, so a name that happens to be numeric can still be resolved. Returns the same shape as a one-off mrql call: either a standard result with an entityType plus the matching entity arrays, or -- for GROUP BY queries -- a grouped result with mode (aggregated or bucketed) and rows / groups.

An aggregated result also carries columns: the column names in the order the query wrote them, group-by fields first and then aggregates. The table output and mrql export --format csv both follow it, so the two agree. Read columns rather than the key order of a rows entry -- a JSON object carries no order.

A bucketed result carries keyColumns for the same reason: the group-by key names in the order the query wrote them. The per-bucket header line and the CSV export's leading columns both follow it. A bucket's key object may hold entries keyColumns does not name -- a bucket keyed on a relation field also gets <field>_id so two same-named groups stay apart -- and those are printed after the named ones.

Pagination and shaping flags (--limit, --buckets, --offset, plus the global --page) apply to the stored query exactly as they would to an inline mrql invocation. Pass --render to request server-side template rendering via the CustomMRQLResult template. A missing ID or name returns HTTP 404.

If the saved query contains $name parameter placeholders, bind them with repeatable --param name=value flags. Every placeholder must be supplied or the run returns HTTP 400.

This is distinct from query run, which executes SQL-backed Query records rather than MRQL DSL expressions.

Usage

mr mrql run <name-or-id>

Positional arguments:

  • <name-or-id>

Examples

Run a saved query by ID

mr mrql run 42

Run by name with bucketed GROUP BY pagination

mr mrql run "resources-by-type" --buckets 5

Run and extract result ids with jq

mr mrql run "recent-photos" --json | jq -r '.resources[].ID'

Flags

FlagTypeDefaultDescription
--limitint0Items per bucket for GROUP BY, or total items for regular queries
--bucketsint0Groups per page for bucketed GROUP BY queries
--offsetint0Bucket offset for cursor-based GROUP BY pagination
--renderboolfalseRequest server-side template rendering via CustomMRQLResult
--paramstringArray[]Bind a query parameter placeholder, repeatable: --param name=value

Inherited global flags

FlagTypeDefaultDescription
--jsonboolfalseOutput raw JSON
--no-headerboolfalseOmit table headers
--pageint1Page number for list commands (default page size: 50)
--quietboolfalseOnly output IDs
--serverstringhttp://localhost:8181mahresources server URL (env: MAHRESOURCES_URL)

Output

MRQL result object with entityType (string) and resources/notes/groups arrays, or a grouped result with mode + rows/groups for GROUP BY queries

Exit Codes

0 on success; 1 on any error

See Also