Officially out now: The TypeDB 3.0 Roadmap >>

Sort operator

The sort operator sorts the input stream based on the variables and their sort order.

Sorting requires the server to fetch all results, sort them, then proceed in the pipeline. This may have significant query performance impact.

Syntax

The sort direction may be specified explicitly to be ascending (asc) or descending (desc). The default sort direction when not specified is ascending.

sort <var> [asc|desc] [ , <var> [asc|desc] ... ];

Example

Retrieve all posts on a given page, sorted from newest to oldest.

match
  $page isa page, has page-id "<page id>";
  $post isa post, has creation-timestamp $created;
  (page: $page, post: $post) isa posting;
sort $created desc;