Query Variables

Results can be stored in variables and used elsewhere in the query.

Variables are declared by

var_name as some_block { ... }

where var_name is any distinct variable name andsome_block is either a whole query or an internal block of a query matching on an edge.

Once defined, variables can be used in:

  • the same query in a child of the defining block (not a parent of the definition)
  • in another query

Variables don’t affect the semantics of the query at the point they are defined.

Query variables are used by uid(<variable-name>). Variables evaluate to all uid’s matched in the query by the block they are defined against. In particular, note that, variables are uid lists, not the graph matched by the block, and that the variable evaluates to all uid’s the block matches for the whole query, not the uid’s matched by any one branch.

It is an error to define a variable but not use it.

Let’s look at the options for query variables in turn.

Endpoint: /query