Reading data
NamiDB implements a strict subset of openCypher 9 plus GQL (ISO/IEC 39075:2024). Every LDBC SNB Interactive Complex Read query (IC01 through IC12) parses, plans, and runs end to end on top of this surface, so the read clauses below are well exercised in practice.
For the precise parser coverage and known gaps, see Supported subset. For the operator and function catalog, see Operators & functions.
MATCH
The basic pattern-matching clause. Variables in () bind nodes; variables
in [] bind relationships.
MATCH (p:Person)RETURN p.namePatterns can chain through relationships:
MATCH (a:Person)-[:KNOWS]->(b:Person)RETURN a.name AS a, b.name AS bMultiple labels and inline property predicates:
MATCH (p:Person {name: 'Alice'})-[:KNOWS]->(friend:Person)WHERE friend.age >= 18RETURN friend.nameVariable-length relationship patterns (bounded):
MATCH (a:Person {name: 'Alice'})-[:KNOWS*1..3]->(reach:Person)RETURN DISTINCT reach.nameWHERE
Filters bound rows. Supports comparison operators (=, <>, <, <=,
>, >=), boolean operators (AND, OR, NOT), IN, IS NULL /
IS NOT NULL, string predicates (STARTS WITH, ENDS WITH, CONTAINS),
and property access (n.prop).
MATCH (p:Person)WHERE p.age >= 18 AND p.country IN ['US', 'CA', 'MX'] AND p.name STARTS WITH 'A'RETURN p.name, p.ageWHERE can appear after MATCH, OPTIONAL MATCH, or WITH. The
optimizer pushes predicates down toward the storage layer so that bloom
filters, fence pointers, and Parquet row-group pruning can skip work.
OPTIONAL MATCH
Like MATCH, but if the pattern fails to bind, columns from the optional
pattern become NULL instead of dropping the row. Left-join semantics.
MATCH (p:Person)OPTIONAL MATCH (p)-[:OWNS]->(car:Car)RETURN p.name, car.modelWITH
Pipes intermediate results into the next clause. Use it to project before
chaining another MATCH, to filter on an aggregation, or to break a query
into stages.
MATCH (p:Person)-[:KNOWS]->(friend)WITH p, count(friend) AS friend_countWHERE friend_count > 5RETURN p.name, friend_countORDER BY friend_count DESCRETURN
Projects the final columns. Supports aliasing (AS), DISTINCT,
expressions, and aggregations.
MATCH (p:Person)RETURN DISTINCT p.country AS country, count(*) AS nORDER BY n DESCLIMIT 10Common shapes:
RETURN p -- whole nodeRETURN p.name, p.age -- propertiesRETURN p.name AS name -- aliasedRETURN p.first_name + ' ' + p.last -- expressionRETURN count(*) AS n -- aggregateORDER BY, SKIP, LIMIT
Sorting and paging. Chain on RETURN (or WITH).
MATCH (p:Person)RETURN p.name, p.ageORDER BY p.age DESCSKIP 20LIMIT 10Multiple sort keys, mixed directions:
MATCH (p:Person)RETURN p.country, p.age, p.nameORDER BY p.country ASC, p.age DESCAggregations
The standard set: count(*), count(expr), sum, avg, min, max,
collect.
MATCH (p:Person)-[:LIVES_IN]->(city:City)RETURN city.name AS city, count(p) AS people, avg(p.age) AS avg_ageORDER BY people DESCcollect(expr) accumulates rows into a list, useful for shaping output:
MATCH (p:Person)-[:KNOWS]->(friend)RETURN p.name, collect(friend.name) AS friendsDISTINCT works inside aggregates:
MATCH (p:Person)-[:LIVES_IN]->(city:City)RETURN count(DISTINCT city) AS citiesEXISTS (subquery)
Tests whether a pattern exists, without materializing it. The optimizer decorrelates this into a hash semi-join (RFC-014) so it runs in a single pass.
MATCH (p:Person)WHERE EXISTS { MATCH (p)-[:KNOWS]->(:Person {country: 'MX'})}RETURN p.nameUNWIND
Expands a list into rows. Useful for joining external data (parameters) into a pattern.
UNWIND $names AS nameMATCH (p:Person {name: name})RETURN p.name, p.agePlan inspection
Add EXPLAIN VERBOSE to any query to see the chosen plan, selectivity
estimates, and per-operator cost annotations:
namidb explain --verbose \ "MATCH (a:Person)-[:KNOWS]->(b) RETURN b ORDER BY b.id LIMIT 20"Plan inspection touches the parser, lowerer, and optimizer but not storage, so it’s safe to run against a production namespace without I/O.
See the CLI page for the full explain flag
reference.
What’s next
- Writing data —
CREATE,MERGE,SET,DELETE. - Operators & functions — the complete operator and built-in function reference.
- Supported subset — the exact slice of openCypher / GQL that NamiDB parses.