FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard. For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions. |
Range
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Range( set, start, end )
range( set, start, end )
Range( set, start, end )
Range( set, start, end )
Range( set, start, end )
Range( set, start, end )
Description
The Range
function returns an inclusive subset of the values from
the provided set
that includes the range of values starting from
start
up to (and including) end
, as defined by the order of the
set
.
For the set of letters, in ascending order, setting start
to F
and
end
to M
results in the subset of letters including F
to M
:
For the set of letters, in descending order, setting start
to M
and
end
to F
results in the subset of letters including M
to F
:
Items in the set
can be:
-
single, scalar values
-
tuples containing a variety of values of different types
start
and end
are expressed as prefixes that need to match some, or
all, of the structure provided by the set
, or Range
returns an
empty set. Prefix-based matching means that, if your set contains two or
more fields, you only need to specify the first field in start
or
end
to achieve a match. You may have to specify additional fields if
there are multiple entries in the set that would match the first field.
For example, if an index’s values
field contains last
and first
fields, start
or end
can be expressed as just a last
name, or an
array containing the last and first names to mark a boundary of the
range.
When start
or end
match an entry in the set
, that’s where the
boundary for the range is set; no further evaluation is done.
Both start
and end
can be expressed as an empty array, which
indicates that the range should extend to, respectively, the set’s first
item, or the set’s last item. If both start
and end
are expressed as
an empty arrange, the entire range is returned.
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
Set |
The Set of items to process. |
|
Value, or Array of Values |
The Value(s) marking the start of the range to return. Use an empty Array to indicate that |
|
Value, or Array of Values |
The Value(s) marking the end of the range to return. Use an empty Array to indicate that |
Examples
With a collection containing the letters of the alphabet, and an index
with a values
field defined to contain each document’s letter
field,
the following query returns the range of values from F
to M
:
{ data: [ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M' ] }
{'data': ['F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']}
map[data:[F G H I J K L M]]
ObjectV(data: Arr(StringV(F), StringV(G), StringV(H), StringV(I), StringV(J), StringV(K), StringV(L), StringV(M)))
{data: ["F", "G", "H", "I", "J", "K", "L", "M"]}
{ data: [
'F', 'G', 'H',
'I', 'J', 'K',
'L', 'M'
] }
With the same setup, the following query returns all of the letters up
to, and including, M
:
{ data:
[ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M' ] }
{'data': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']}
map[data:[A B C D E F G H I J K L M]]
ObjectV(data: Arr(StringV(A), StringV(B), StringV(C), StringV(D), StringV(E), StringV(F), StringV(G), StringV(H), StringV(I), StringV(J), StringV(K), StringV(L), StringV(M)))
{data: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"]}
{
data: [
'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L',
'M'
]
}
With the same setup, the following query returns F
and all of the
subsequent letters:
{ data:
[ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ] }
{'data': ['F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']}
map[data:[F G H I J K L M N O P Q R S T U V W X Y Z]]
ObjectV(data: Arr(StringV(F), StringV(G), StringV(H), StringV(I), StringV(J), StringV(K), StringV(L), StringV(M), StringV(N), StringV(O), StringV(P), StringV(Q), StringV(R), StringV(S), StringV(T), StringV(U), StringV(V), StringV(W), StringV(X), StringV(Y), StringV(Z)))
{data: ["F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]}
{
data: [
'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y',
'Z'
]
}
The schema setup is not documented here. Most of what you need to make this example work is included in the Index tutorials, including the creation of the collection and the creation of the letters documents. You would need to create an appropriate index, which should look like this:
|
With a collection containing people, with first and last names, and an
index with a values
field defined to contain the last
and first
fields, the following query returns all of the people from Hopper
to
Minsky
:
{ data:
[ [ 'Hopper', 'Grace' ],
[ 'Lamport', 'Leslie' ],
[ 'Minsky', 'Marvin' ] ] }
{'data': [['Hopper', 'Grace'], ['Lamport', 'Leslie'], ['Minsky', 'Marvin']]}
map[data:[[Hopper Grace] [Lamport Leslie]]]
ObjectV(data: Arr(Arr(StringV(Hopper), StringV(Grace)), Arr(StringV(Lamport), StringV(Leslie)), Arr(StringV(Minsky), StringV(Marvin))))
{data: [["Hopper", "Grace"], ["Lamport", "Leslie"], ["Minsky", "Marvin"]]}
{
data: [
[ 'Hopper', 'Grace' ],
[ 'Lamport', 'Leslie' ],
[ 'Minsky', 'Marvin' ]
]
}
See the Index tutorials for
the setup of the
|
With a collection containing people, with age, and first and last names,
and an index with a values
field defined to contain the age
and
first
fields, the following query returns all of the people from 80,
Leslie
to 92, Marvin
:
{ data: [ [ 80, 'Leslie' ], [ 81, 'Stephen' ], [ 92, 'Marvin' ] ] }
{'data': [[80, 'Leslie'], [81, 'Stephen'], [92, 'Marvin']]}
map[data:[[80 Leslie] [81 Stephen] [92 Marvin]]]
ObjectV(data: Arr(Arr(LongV(80), StringV(Leslie)), Arr(LongV(81), StringV(Stephen)), Arr(LongV(92), StringV(Marvin))))
{data: [[80, "Leslie"], [81, "Stephen"], [92, "Marvin"]]}
{ data: [ [ 80, 'Leslie' ], [ 81, 'Stephen' ], [ 92, 'Marvin' ] ] }
If we repeat the query, but only use the person’s age in the range, the same result is returned:
{ data: [ [ 80, 'Leslie' ], [ 81, 'Stephen' ], [ 92, 'Marvin' ] ] }
{'data': [[80, 'Leslie'], [81, 'Stephen'], [92, 'Marvin']]}
map[data:[[80 Leslie] [81 Stephen] [92 Marvin]]]
ObjectV(data: Arr(Arr(LongV(80), StringV(Leslie)), Arr(LongV(81), StringV(Stephen)), Arr(LongV(92), StringV(Marvin))))
{data: [[80, "Leslie"], [81, "Stephen"], [92, "Marvin"]]}
{ data: [ [ 80, 'Leslie' ], [ 81, 'Stephen' ], [ 92, 'Marvin' ] ] }
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!