Search
ctrl/
Ask AI
Light
Dark
System

Scalar Types

This section describes the DDL commands pertaining to scalar types.

Define a new scalar type.

[ with with-item [, ...] ]
create [abstract] scalar type name [ extending supertype ]
[ "{" subcommand; [...] "}" ] ;

where subcommand is one of

  create annotation annotation-name := value
  create constraint constraint-name ...

The command create scalar type defines a new scalar type for use in the current database.

If name is qualified with a module name, then the type is created in that module, otherwise it is created in the current module. The type name must be distinct from that of any existing schema item in the module.

If the abstract keyword is specified, the created type will be abstract.

All non-abstract scalar types must have an underlying core implementation. For user-defined scalar types this means that create scalar type must have another non-abstract scalar type as its supertype.

The most common use of create scalar type is to define a scalar subtype with constraints.

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

create annotation annotation-name := value;

Set scalar type’s annotation-name to value.

See create annotation for details.

create constraint constraint-name ...

Define a new constraint for this scalar type. See create constraint for details.

Create a new non-negative integer type:

Copy
create scalar type posint64 extending int64 {
    create constraint min_value(0);
};

Create a new enumerated type:

Copy
create scalar type Color
    extending enum<Black, White, Red>;

Alter the definition of a scalar type.

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

where subcommand is one of

  rename to newname
  extending ...
  create annotation annotation-name := value
  alter annotation annotation-name := value
  drop annotation annotation-name
  create constraint constraint-name ...
  alter constraint constraint-name ...
  drop constraint constraint-name ...

The command alter scalar type changes the definition of a scalar type. name must be a name of an existing scalar type, optionally qualified with a module name.

The following subcommands are allowed in the alter scalar type block:

rename to newname;

Change the name of the scalar type to newname.

extending ...

Alter the supertype list. It works the same way as in alter type.

alter annotation annotation-name;

Alter scalar type annotation-name. See alter annotation for details.

drop annotation annotation-name

Remove scalar type’s annotation-name from value. See drop annotation for details.

alter constraint constraint-name ...

Alter the definition of a constraint for this scalar type. See alter constraint for details.

drop constraint constraint-name

Remove a constraint from this scalar type. See drop constraint for details.

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

Define a new constraint on a scalar type:

Copy
alter scalar type posint64 {
    create constraint max_value(100);
};

Add one more label to an enumerated type:

Copy
alter scalar type Color
    extending enum<Black, White, Red, Green>;

Remove a scalar type.

[ with with-item [, ...] ]
drop scalar type name ;

The command drop scalar type removes a scalar type.

name

The name (optionally qualified with a module name) of an existing scalar type.

Remove a scalar type:

Copy
drop scalar type posint64;