RETURN clause

RETURN indicates that the statement result should be included in the query result.

All EQL statements begin with either DEFINE or RETURN.

RETURN provides the key for accessing EQL results from the Dgraph query result. This is important when more than one statement is submitted with the query.

The RETURN syntax is:
RETURN <statementName> AS ...
Note that the statement name cannot be the same as the state name or as any other statement.
The following statement returns for each size the number of different values for the Color attribute:
RETURN Result AS 
SELECT COUNTDISTINCT(Color) AS Total
FROM ProductState
GROUP BY Size

WITH UNPAGED COUNT modifier

A RETURN clause can include an optional WITH UNPAGED COUNT modifier that computes the unpaged (total) record count for the statement and returns the count as in a NumRecords element in the results metadata. The syntax is:
RETURN <statementName> WITH UNPAGED COUNT AS ...
Assume, for example, this query:
RETURN Results WITH UNPAGED COUNT AS
SELECT
   WineType AS types,
   Flavors AS tastes
FROM winestate
If 50 records are returned, the metadata in the results would include this element:
NumRecords="50"

It would then be the responsibility of the application to parse this element and print number for the application's UI. Note that NumRecords will still be 50 if you add, say PAGE(0,10) to the statement.

Note the following about this parameter:
  • WITH UNPAGED COUNT can be used in a statement with a PAGE clause.
  • WITH UNPAGED COUNT is ignored if used in a DEFINE statement.