New ACM paper, free-tier cloud, and open-source license

Lesson 3: Reading data

In this lesson, we’ll learn how to read pre-inserted data in the sample database using Fetch queries. We’ll begin by seeing how we can retrieve entities and relations in a similar way to how we do with relational databases. We’ll then see how we can retrieve data in unique ways using TypeDB: by writing declarative polymorphic queries, by leveraging rule inference, and by retrieving types from the schema. Finally, we’ll look at a few examples of type inference at work by seeing how TypeDB validates queries.

  • You should complete Lesson 2 before starting this lesson.

Lesson contents

Learn how to retrieve the attributes of entities and relations.

Learn how to retrieve data with polymorphic queries.

Learn how to retrieve data generated by rule inference.

Learn how to retrieve typing information from the schema.

Learn about how queries are validated against the schema.

Running examples

To run a Fetch query, make sure to use a data session and read transaction. The examples and exercises featured in this lesson are annotated with one of the following instructions to indicate how they should be run.

studio run Run

Run this query. Read transactions do not need to be committed.

studio run Try running

Run this query to see the error generated.

For information on how to control sessions, transactions, and queries using TypeDB Studio, refer back to Lesson 2.2.

TypeQL keywords introduced

  • match

  • fetch

  • attribute

  • isa

  • has

  • entity

  • relation

  • isa!

  • sub

  • sub!

  • owns

  • relates

  • plays

Provide Feedback