LIMIT constrains the number of rows returned by a Cypher query. It accepts any expression that evaluates to a positive integer, as long as the expression does not reference external variables.
Return a fixed number of rows
Pass a literal integer to cap the result set.
Example 1. Return the first three rows
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 nodes, ordered alphabetically, capped at three rows.
| names |
|---|
| "A" |
| "B" |
| "C" |
(3 rows)
Return a variable number of rows using an expression
Pass an expression to make the limit dynamic. The expression must evaluate to a positive integer and must not reference any external variables.
Example 2. Return between one and three rows using a random limit
SELECT *
FROM cypher('graph_name', $$
MATCH (n)
RETURN n.name
ORDER BY n.name
LIMIT toInteger(3 * rand()) + 1
$$) as (names agtype);toInteger(3 * rand()) + 1 evaluates to a random integer between 1 and 3. The following is an example result:
| names |
|---|
| "A" |
| "B" |
(2 rows)
该文章对您有帮助吗?