Search
ctrl/
Ask AI
Light
Dark
System

Paths

A path expression (or simply a path) represents a set of values that are reachable by traversing a given sequence of links or properties from some source set of objects.

Consider the following schema:

Copy
type User {
  required email: str;
  multi friends: User;
}

type BlogPost {
  required title: str;
  required author: User;
}

type Comment {
  required text: str;
  required author: User;
}

A few simple inserts will allow some experimentation with paths.

Start with a first user:

Copy
db> 
... 
... 
insert User {
email := "user1@me.com",
};

Along comes another user who adds the first user as a friend:

Copy
db> 
... 
... 
... 
insert User {
email := "user2@me.com",
friends := (select detached User filter .email = "user1@me.com")
};

The first user reciprocates, adding the new user as a friend:

Copy
db> 
... 
... 
... 
update User filter .email = "user1@me.com"
set {
friends += (select detached User filter .email = "user2@me.com")
};

The second user writes a blog post about how nice EdgeDB is:

Copy
db> 
... 
... 
... 
insert BlogPost {
title := "EdgeDB is awesome",
author := assert_single((select User filter .email = "user2@me.com"))
};

And the first user follows it up with a comment below the post:

Copy
db> 
... 
... 
... 
insert Comment {
text := "Nice post, user2!",
author := assert_single((select User filter .email = "user1@me.com"))
};

The simplest path is simply User. This is a set reference that refers to all User objects in the database.

Copy
select User;

Paths can traverse links. The path below refers to all Users who are the friend of another User.

Copy
select User.friends;

Paths can traverse to an arbitrary depth in a series of nested links. Both select queries below end up showing the author of the BlogPost. The second query returns the friends of the friends of the author of the BlogPost, which in this case is just the author.

Copy
select BlogPost.author; # The author
select BlogPost.author.friends.friends; # The author again

Paths can terminate with a property reference.

Copy
select BlogPost.title; # all blog post titles
select BlogPost.author.email; # all author emails
select User.friends.email; # all friends' emails

For simplicity, all examples above use set references like User as the root of the path; however, the root can be any expression returning object types. Below, the root of the path is a subquery.

Copy
db> 
... 
... 
... 
with edgedb_lovers := (
  select BlogPost filter .title ilike "EdgeDB is awesome"
)
select edgedb_lovers.author;

This expression returns a set of all Users who have written a blog post titled “EdgeDB is awesome”.

For a full syntax definition, see the Reference > Paths.