Search
ctrl/
Ask AI
Light
Dark
System

Primitives

EdgeDB has a robust type system consisting of primitive and object types. Below is a review of EdgeDB’s primitive types; later, these will be used to declare properties on object types.

str

A variable-length string

bool

Logical boolean (true/false)

int16

16-bit integer

int32

32-bit integer

int64

64-bit integer

float32

32-bit floating point number

float64

64-bit floating point number

bigint

Arbitrary precision integer

decimal

Arbitrary precision number

json

Arbitrary JSON data

uuid

UUID type

bytes

Raw binary data

datetime

Timezone-aware point in time

duration

Absolute time span

cal::local_datetime

Date and time without timezone

cal::local_date

Date type

cal::local_time

Time type

cal::relative_duration

Relative time span (in months, days, and seconds)

cal::date_duration

Relative time span (in months and days only)

sequence

Auto-incrementing sequence of int64

Custom scalar types can also be declared. For full documentation, see SDL > Scalar types.

To represent an enum, declare a custom scalar that extends the abstract enum type.

Copy
scalar type Color extending enum<Red, Green, Blue>;

type Shirt {
  color: Color;
}

To reference enum values inside EdgeQL queries, use dot notation, e.g. Color.Green.

For a full reference on enum types, see the Enum docs.

Arrays store zero or more primitive values of the same type in an ordered list. Arrays cannot contain object types or other arrays.

Copy
type Person {
  str_array: array<str>;
  json_array: array<json>;

  # INVALID: arrays of object types not allowed
  # friends: array<Person>

  # INVALID: arrays cannot be nested
  # nested_array: array<array<str>>
}

For a full reference on array types, see the Array docs.

Like arrays, tuples are ordered sequences of primitive data. Unlike arrays, each element of a tuple can have a distinct type. Tuple elements can be any type, including primitives, objects, arrays, and other tuples.

Copy
type Person {

  unnamed_tuple: tuple<str, bool, int64>;
  nested_tuple: tuple<tuple<str, tuple<bool, int64>>>;
  tuple_of_arrays: tuple<array<str>, array<int64>>;

}

Optionally, you can assign a key to each element of the tuple. Tuples containing explicit keys are known as named tuples. You must assign keys to all elements (or none of them).

Copy
type BlogPost {
  metadata: tuple<title: str, published: bool, upvotes: int64>;
}

Named and unnamed tuples are the same data structure under the hood. You can add, remove, and change keys in a tuple type after it’s been declared. For details, see EdgeQL > Literals > Tuples.

When you query an unnamed tuple using one of EdgeQL’s client libraries, its value is converted to a list/array. When you fetch a named tuple, it is converted into an object/dictionary/hashmap depending on the language.

Ranges represent some interval of values. The intervals can be bound or unbound on either end. They can also be empty, containing no values. Only some scalar types have corresponding range types:

  • range<int32>

  • range<int64>

  • range<float32>

  • range<float64>

  • range<decimal>

  • range<datetime>

  • range<cal::local_datetime>

  • range<cal::local_date>

Copy
type DieRoll {
  values: range<int64>;
}

For a full reference on ranges, functions and operators see the Range docs.

To represent an auto-incrementing integer property, declare a custom scalar that extends the abstract sequence type. Creating a sequence type initializes a global int64 counter that auto-increments whenever a new object is created. All properties that point to the same sequence type will share the counter.

Copy
scalar type ticket_number extending sequence;
type Ticket {
  number: ticket_number;
}

For a full reference on sequences, see the Sequence docs.