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 ...

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 ...

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 ;

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;
Light
Dark
System