LIMIT

The LIMIT clause restricts the number of records returned in the result set.

Introduction

LIMIT accepts any expression that evaluates to a positive integer.

Returning a Subset of Rows

To return the top n rows of a result set, use the following syntax:

Query

SELECT *
FROM cypher('graph_name', $$
        MATCH (n) RETURN n.name
        ORDER BY n.name
        LIMIT 3
$$) AS (names agtype);

Returns the name property of matched vertices n, limited to three rows.

Result

names
"A"
"B"
"C"
3 rows

Using Expressions with LIMIT

LIMIT accepts any expression that evaluates to a positive integer, provided it does not reference external variables.

Query

SELECT *
FROM cypher('graph_name', $$
        MATCH (n)
        RETURN n.name
        ORDER BY n.name
        LIMIT toInteger(3 * rand()) + 1
$$) AS (names agtype);

Returns one to three top-ranked rows.

Result

names
"A"
"B"
2 rows