EdgeDB 1.0 is launching on Feb 10th! Watch the live event.
Claim your ticket

This section describes the DDL commands pertaining to indexes.

Define an new index for a given object type or link.

CREATE INDEX ON ( index-expr )
[ "{" subcommand; [...] "}" ] ;

where subcommand is one of

  CREATE ANNOTATION annotation-name := value

CREATE INDEX constructs a new index for a given object type or link using index-expr.

Most sub-commands and options of this command are identical to the SDL index declaration. There’s only one subcommand that is allowed in the CREATE INDEX block:

CREATE ANNOTATION annotation-name := value

Set object type annotation-name to value.

See CREATE ANNOTATION for details.

Create an object type User with an indexed name property:

Copy
CREATE TYPE User {
    CREATE PROPERTY name -> str {
        SET default := '';
    };

    CREATE INDEX ON (.name);
};

Alter the definition of an index.

ALTER INDEX ON ( index-expr )
[ "{" subcommand; [...] "}" ] ;

where subcommand is one of

  CREATE ANNOTATION annotation-name := value
  ALTER ANNOTATION annotation-name := value
  DROP ANNOTATION annotation-name

ALTER INDEX is used to change the annotations of an index. The index-expr is used to identify the index to be altered.

ON ( index-expr )

The specific expression for which the index is made. Note also that <index-expr> itself has to be parenthesized.

The following subcommands are allowed in the ALTER INDEX block:

CREATE ANNOTATION annotation-name := value

Set index annotation-name to value. See CREATE ANNOTATION for details.

ALTER ANNOTATION annotation-name;

Alter index annotation-name. See ALTER ANNOTATION for details.

DROP ANNOTATION annotation-name;

Remove constraint annotation-name. See DROP ANNOTATION for details.

Add an annotation to the index on the name property of object type User:

Copy
ALTER TYPE User {
    ALTER INDEX ON (.name) {
        CREATE ANNOTATION title := "User name index";
    };
};

Remove an index from a given schema item.

DROP INDEX ON ( index-expr );

DROP INDEX removes an index from a schema item.

ON ( index-expr )

The specific expression for which the index was made.

This statement can only be used as a subdefinition in another DDL statement.

Drop the name index from the User object type:

Copy
ALTER TYPE User {
    DROP INDEX ON (.name);
};
Light
Dark
System