SpydQL Overview
Composable pipeline stages, CTEs, joins, scalar functions, positional parameters, and query profiling.
SpydQL is SpydDB's composable pipeline query language. Every statement reads top-to-bottom as a clean sequence of pipe stages (|), operating inside a single MVCC + Serializable Snapshot Isolation (SSI) transaction across row collections, columnar segments, full-text BM25 indexes, HNSW vectors, and R-Tree spatial indexes.
Pipeline Anatomy#
Data flows left-to-right from a collection, view, or CTE through filtering, enrichment, grouping, ordering, and projection stages:
orders
| where status == "paid" and placed_at >= $1
| join customers on orders.customer_id == customers.id
| group by customers.tier
| agg count() as order_count, sum(orders.total) as revenue, avg(orders.total) as aov
| where revenue >= 500
| sort revenue desc
| take 20
| skip 0Complete Pipeline Operators Reference#
| Stage | Purpose | Example |
|---|---|---|
<source> | Collection, view, materialized view, external table, table-valued function, CTE, or system | orders / my_tvf($1) / system |
where <expr> | Row or post-aggregate predicate filter | where total >= 100 and status != "void" |
get <pk>=<val>, ... | Direct primary-key lookup | get tenant_id=7, id=42 |
pick <expr> [as alias], ... | Explicit column projection (wildcard * is omitted) | pick id, upper(country) as cc |
extend <expr> as name, ... | Append computed columns while preserving existing fields | extend total * 1.1 as with_tax |
omit field, ... | Drop specific fields from pipeline output | omit internal_secret, raw_blob |
rename old as new, ... | Rename fields downstream in the pipeline | rename ts as event_time |
sort [-]<expr> [asc | desc] [nulls first | last] | Multi-column sorting (leading - sorts descending) | sort priority desc, created_at asc nulls last |
take <n> / skip <n> | Bound and offset result count (limit / offset also accepted in Cypher MATCH) | take 25 | skip 50 |
distinct [<expr>, ...] | Deduplicate entire rows or by explicit key expressions | distinct / distinct customer_id |
group by <item>, ... | Group keys, rollup(...), cube(...), or grouping sets(...) | group by rollup(region, category) |
agg <exprs> [by <item>, ...] | Exact & approximate aggregates + custom UDAs (create aggregate) | agg count() as n, sum(total) as rev |
count | Return single u64 row count of current stream | orders | where paid == true | count |
window <fn> over (...) as name | Ranking, offset (lag/lead), and framed running aggregates | window row_number() over (partition by dept sort by -salary) as rk |
unnest <array> as name | Expand array elements into one row per element | unnest tags as tag |
join / left_join / right_join / full_join / cross_join / semi_join / anti_join | Relational joins across collections, TVFs, subqueries, and external tables | semi_join active_users on orders.user_id == active_users.id |
union [all] / intersect [all] / except [all] | Set operations across compatible pipelines | union all (archived_orders) |
walk / shortest_path / pagerank / components / strongly_connected_components / graph_degree / graph_communities / graph_betweenness / graph_closeness / graph_triangles | Native graph traversal and graph analytics over edge collections | walk out from $1 3 over src, dst |
insert / upsert on / set / delete / returning | Atomic ACID mutations and post-write projection | set { status: "paid" } | returning id |
lock_rows update | share [of ...] [nowait | skip_locked] | Row-level pessimistic locking before limit truncation | lock_rows update skip_locked |
consistency <level> | Per-query isolation/read consistency override (serializable, snapshot, read_committed, read_your_writes, eventual) | consistency eventual |
hint index(<idx>) | Advise planner to select a named index scan | hint index(idx_orders_created) |
explain [analyze] | Inspect logical/physical plan and per-operator runtime telemetry | explain analyze orders | where id == 42 |
Deep-dive manuals:
- All 70+ Built-in Functions
- Window Functions, Rollups, CTEs & Merge
- Property Graph (
MATCH) & Algorithms - Stored Procedures & PL/pgSQL
- Functions, WASM UDFs & Custom Aggregates
Common Table Expressions (with)#
Compose multi-stage logic or combine vector nearest-neighbor candidate sets with relational and full-text filters using with ... as (...):
with vip_customers as (
customers | where lifetime_spend >= 10000 | pick id, name
)
| orders
| where customer_id in (vip_customers | pick id) and status == "paid"
| pick id, total, placed_at
| sort total desc
| take 25Expressions, Operators & Functions#
Comparison & Boolean Logic#
- Equality & comparison:
==,!=,<,<=,>,>=(standard SQL=is accepted where applicable; SpydQL idioms use==) - Pattern & set matching:
like,between ... and ...,in (...),not in (...),is null,is not null - Logical operators:
and,or,not - Conditional branching:
orders
| pick id,
case
when total >= 1000 then "enterprise"
when total >= 100 then "standard"
else "small"
end as tierBuilt-in Function Families#
| Category | Key Functions |
|---|---|
| Strings & Text | lower, upper, trim, ltrim, rtrim, length/len, substring/substr, left, right, concat, replace, starts_with, ends_with, contains, domain, tokenize |
| Numbers & Ledgers | abs, round, floor, ceil, sqrt, power/pow, greatest, least, coalesce, nullif, cast(expr as type), balance_delta(bal, min, max, d1, ...) |
| Dates & Time-Series | now(), time_bucket(ts, interval), extract("field", ts), date_trunc("unit", ts), second, minute, hour, day, week, month, year |
| JSON, Hstore, Array & Range | json_get, json_text, hstore_get, hstore_has_key, hstore_keys, hstore_values, array_length, array_contains, int4range, int8range, daterange, tsrange, range_contains, range_overlaps, lower, upper, is_empty |
| Search & Hybrid Fusion | match/search, partial_match, partial_score, should_match, multi_match, multi_score, fuzzy_match, phrase_match, synonym_match, contains_token, score, highlight/highlight_natural/highlight_partial, snippet/snippet_natural/snippet_partial, rrf, hybrid_score |
| Vector, Spatial & ML | nearest, vector_distance, vector_similarity, vector_dot, vector_norm, vector_normalize, vector_centroid, geo_distance, geo_within, geo_contains, geo_radius, geo_near, ml_score, ml_class |
See the complete signature & type table in SpydQL Built-in Functions Reference.
Parameterized Queries ($1, $2, ...)#
Always bind user inputs with positional placeholders ($1, $2, ...) instead of interpolating literals:
orders
| where customer_id == $1 and status in ($2, $3) and total >= cast($4 as decimal(12, 2))
| pick id, status, total, placed_at
| sort placed_at desc
| take 50Note that decimal parameters passed over JSON or dynamic wire requests should either use explicit cast($n as decimal(p, s)) or a typed ORM field / binary SPD2 Decimal value so exact scale is preserved without floating-point rounding.
Query Execution Plans & Profiling#
Inspect index usage, join strategy, candidate-set intersection, and runtime bottlenecks:
explain orders | where status == "paid" and match(notes, "express") | pick id
explain analyze
events
| where ts >= "2026-01-01T00:00:00Z"
| group by service
| agg count() as reqs, avg(latency_ms) as avg_msexplain analyze appends measured row counts and inclusive elapsed execution time for every physical operator.