Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

Primitive result statement

The primitive result statement defines the final output behavior of a linear query:

  • Return data, optionally with paging.
  • Or end the query directly without returning data.

Syntax

primitive_result
return_statement paging_statement FINISH

primitive_result ::=
    return_statement paging_statement?
  | FINISH

Parameters

return_statement

Selects query results or performs aggregation on the query results. For more information, see RETURN statement.

paging_statement

Splits the query result dataset into discrete subsets, or pages. For more information, see Paging statements.

FINISH

The FINISH clause ends the query without returning query data.

Examples

Return distinct results with paging

'''
LET nums = LIST[5, 3, 1, 4, 2, 2]
FOR i IN nums
RETURN DISTINCT i AS num
ORDER BY num ASC
OFFSET 1
LIMIT 2
'''

The preceding statement first expands the list nums, then uses RETURN DISTINCT to return unique results, and applies ORDER BY and OFFSET for paging. Finally, it returns the first 2 rows of the remaining result set.

Return:

+-----+
| num |
+-----+
| 2   |
| 3   |
+-----+

End a query without returning data

'''
LET nums = LIST[1, 2, 3]
FOR n IN nums
FINISH
'''

The preceding statement first expands the list nums, then uses FINISH to end the query directly without returning any data.

Finish an inline procedure

'''
LET a = 1
CALL {
  LET b = a + 1
  FINISH
}
RETURN a
'''

The preceding statement first defines the variable a, then calls an inline procedure. Inside that procedure, FINISH ends the procedure without returning any inner result, so the final result contains only a from the outer query.

Return:

+---+
| a |
+---+
| 1 |
+---+