take m returns the first m elements (or the whole list if the list has fewer than m elements);
skip n skips the first n elements (or returns the empty list if it has n or fewer elements).
For example,
from e in emps
order e.hiredate
skip 2 take 3
returns the 3rd, 4th and 5th employees hired.
The argument to take and skip are int expressions that are evaluated in the same environment as the from. They can, of course, be literals. But they may not reference variables from the pipeline. For example:
(*) Valid
fun topNEmployeesBySalary n =
from e in emps
order by sal desc take n;
(*) Invalid
from e in emps
take e.deptno
take and skip are equivalent to LIMIT and OFFSET keywords in SQL. It is equivalent to the Postgres SQL
SELECT *
FROM Emp AS e
ORDER BY e.hiredate LIMIT 3 OFFSET 2;
or standard SQL
SELECT *
FROM Emp AS e
ORDER BY e.hiredate OFFSET 2 ROWS FETCH NEXT 3 ROWS ONLY;
Add
take
andskip
relational operators:take m
returns the firstm
elements (or the whole list if the list has fewer thanm
elements);skip n
skips the firstn
elements (or returns the empty list if it hasn
or fewer elements).For example,
returns the 3rd, 4th and 5th employees hired.
The argument to
take
andskip
areint
expressions that are evaluated in the same environment as thefrom
. They can, of course, be literals. But they may not reference variables from the pipeline. For example:take
andskip
are equivalent toLIMIT
andOFFSET
keywords in SQL. It is equivalent to the Postgres SQLor standard SQL