Search
ctrl/
Ask AI
Light
Dark
System

Globals

This section describes the DDL commands pertaining to global variables.

Declare a new global variable.

[ with with-item [, ...] ]
create [{required | optional}] [single]
  global name -> type
    [ "{" subcommand; [...] "}" ] ;

Computed global variable form:

[ with with-item [, ...] ]
create [{required | optional}] [{single | multi}]
  global name := expression;

where subcommand is one of

  set default := expression
  create annotation annotation-name := value

There two different forms of global declaration, as shown in the syntax synopsis above. The first form is for defining a global variable that can be set in a session. The second form is not directly set, but instead it is computed based on an expression, potentially deriving its value from other global variables.

Most sub-commands and options of this command are identical to the SDL global variable declaration. The following subcommands are allowed in the create global block:

set default := expression

Specifies the default value for the global variable as an EdgeQL expression. The default value is used by the session if the value was not explicitly specified or by the reset command.

create annotation annotation-name := value

Set global variable annotation-name to value.

See create annotation for details.

Define a new global property current_user_id:

Copy
create global current_user_id -> uuid;

Define a new computed global property current_user based on the previously defined current_user_id:

Copy
create global current_user := (
    select User filter .id = global current_user_id
);

Change the definition of a global variable.

[ with with-item [, ...] ]
alter global name
  [ "{" subcommand; [...] "}" ] ;

where subcommand is one of

  set default := expression
  reset default
  rename to newname
  set required
  set optional
  reset optionalily
  set single
  set multi
  reset cardinality
  set type typename reset to default
  using (computed-expr)
  create annotation annotation-name := value
  alter annotation annotation-name := value
  drop annotation annotation-name

The command alter global changes the definition of a global variable.

name

The name of the global variable to modify.

The following subcommands are allowed in the alter global block:

reset default

Remove the default value from this global variable.

rename to newname

Change the name of the global variable to newname.

set required

Make the global variable required.

set optional

Make the global variable no longer required (i.e. make it optional).

reset optionalily

Reset the optionality of the global variable to the default value (optional).

set single

Change the maximum cardinality of the global variable to one.

set multi

Change the maximum cardinality of the global variable set to greater than one. Only valid for computed global variables.

reset cardinality

Reset the maximum cardinality of the global variable to the default value (single), or, if the property is computed, to the value inferred from its expression.

set type typename reset to default

Change the type of the global variable to the specified typename. The reset to default clause is mandatory and it specifies that the variable will be reset to its default value after this command.

using (computed-expr)

Change the expression of a computed global variable. Only valid for computed variables.

alter annotation annotation-name;

Alter global variable annotation annotation-name. See alter annotation for details.

drop annotation annotation-name;

Remove global variable annotation-name. See drop annotation for details.

All the subcommands allowed in the create global block are also valid subcommands for alter global block.

Set the description annotation of global variable current_user:

Copy
alter global current_user
    create annotation description :=
        'Current User as specified by the global ID';

Make the current_user_id global variable required:

Copy
alter global current_user_id {
    set required;
    # A required global variable MUST have a default value.
    set default := <uuid>'00ea8eaa-02f9-11ed-a676-6bd11cc6c557';
}

Remove a global variable from the schema.

[ with with-item [, ...] ]
drop global name ;

The command drop global removes the specified global variable from the schema.

Remove the current_user global variable:

Copy
drop global current_user;