SpydQL Overview

Composable pipeline stages, CTEs, joins, scalar functions, positional parameters, and query profiling.

5 min read SpydQL & Data Modeling

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:

spydql
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 0

Complete Pipeline Operators Reference#

StagePurposeExample
<source>Collection, view, materialized view, external table, table-valued function, CTE, or systemorders / my_tvf($1) / system
where <expr>Row or post-aggregate predicate filterwhere total >= 100 and status != "void"
get <pk>=<val>, ...Direct primary-key lookupget 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 fieldsextend total * 1.1 as with_tax
omit field, ...Drop specific fields from pipeline outputomit internal_secret, raw_blob
rename old as new, ...Rename fields downstream in the pipelinerename 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 expressionsdistinct / 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
countReturn single u64 row count of current streamorders | where paid == true | count
window <fn> over (...) as nameRanking, offset (lag/lead), and framed running aggregateswindow row_number() over (partition by dept sort by -salary) as rk
unnest <array> as nameExpand array elements into one row per elementunnest tags as tag
join / left_join / right_join / full_join / cross_join / semi_join / anti_joinRelational joins across collections, TVFs, subqueries, and external tablessemi_join active_users on orders.user_id == active_users.id
union [all] / intersect [all] / except [all]Set operations across compatible pipelinesunion all (archived_orders)
walk / shortest_path / pagerank / components / strongly_connected_components / graph_degree / graph_communities / graph_betweenness / graph_closeness / graph_trianglesNative graph traversal and graph analytics over edge collectionswalk out from $1 3 over src, dst
insert / upsert on / set / delete / returningAtomic ACID mutations and post-write projectionset { status: "paid" } | returning id
lock_rows update | share [of ...] [nowait | skip_locked]Row-level pessimistic locking before limit truncationlock_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 scanhint index(idx_orders_created)
explain [analyze]Inspect logical/physical plan and per-operator runtime telemetryexplain analyze orders | where id == 42

Deep-dive manuals:

Common Table Expressions (with)#

Compose multi-stage logic or combine vector nearest-neighbor candidate sets with relational and full-text filters using with ... as (...):

spydql
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 25

Expressions, 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:
spydql
orders
| pick id,
       case
         when total >= 1000 then "enterprise"
         when total >= 100 then "standard"
         else "small"
       end as tier

Built-in Function Families#

CategoryKey Functions
Strings & Textlower, upper, trim, ltrim, rtrim, length/len, substring/substr, left, right, concat, replace, starts_with, ends_with, contains, domain, tokenize
Numbers & Ledgersabs, round, floor, ceil, sqrt, power/pow, greatest, least, coalesce, nullif, cast(expr as type), balance_delta(bal, min, max, d1, ...)
Dates & Time-Seriesnow(), time_bucket(ts, interval), extract("field", ts), date_trunc("unit", ts), second, minute, hour, day, week, month, year
JSON, Hstore, Array & Rangejson_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 Fusionmatch/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 & MLnearest, 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:

spydql
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 50

Note 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:

spydql
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_ms

explain analyze appends measured row counts and inclusive elapsed execution time for every physical operator.