LIMIT constrains the number of records in the output.

Introduction

LIMIT accepts any expression that evaluates to a positive integer.

Return a subset of the rows

To return a subset of the result, starting from the top, use the following syntax:

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (n) RETURN n.name
  4. ORDER BY n.name
  5. LIMIT 3
  6. $$) as (names agtype);

The name property of the matched node n is returned, with a limit of 3.

Result

names
“A”
“B”
“C”
3 rows

Using an expression with LIMIT to return a subset of the rows

LIMIT accepts any expression that evaluates to a positive integer as long as it is not referring to any external variables:

Query

  1. SELECT *
  2. FROM cypher('graph_name', $$
  3. MATCH (n)
  4. RETURN n.name
  5. ORDER BY n.name
  6. LIMIT toInteger(3 * rand()) + 1
  7. $$) as (names agtype);

Returns one to three top items.

Result

names
“A”
“B”
2 rows