Scalar Types

This section describes the DDL commands pertaining to scalar types.

Create scalar type

Define a new scalar type.

  1. [ with with-item [, ...] ]
  2. create [abstract] scalar type name [ extending supertype ]
  3. [ "{" subcommand; [...] "}" ] ;
  4. where subcommand is one of
  5. create annotation annotation-name := value
  6. create constraint constraint-name ...

Description

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.

Examples

Create a new non-negative integer type:

  1. create scalar type posint64 extending int64 {
  2. create constraint min_value(0);
  3. };

Create a new enumerated type:

  1. create scalar type Color
  2. extending enum<Black, White, Red>;

Alter scalar type

Alter the definition of a scalar type.

  1. [ with with-item [, ...] ]
  2. alter scalar type name
  3. "{" subcommand; [...] "}" ;
  4. where subcommand is one of
  5. rename to newname
  6. extending ...
  7. create annotation annotation-name := value
  8. alter annotation annotation-name := value
  9. drop annotation annotation-name
  10. create constraint constraint-name ...
  11. alter constraint constraint-name ...
  12. drop constraint constraint-name ...

Description

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.

Examples

Define a new constraint on a scalar type:

  1. alter scalar type posint64 {
  2. create constraint max_value(100);
  3. };

Add one more label to an enumerated type:

  1. alter scalar type Color
  2. extending enum<Black, White, Red, Green>;

Drop scalar type

Remove a scalar type.

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

Description

The command drop scalar type removes a scalar type.

Parameters

name

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

Example

Remove a scalar type:

  1. drop scalar type posint64;