alter space

Use alter space command to add a field to an existing space definition, or to add or drop an index from a space definition.

Syntax

alter space <string> add (field name <string> type <string> [nullable <boolean>] 
[encrypted <boolean>](, field name <string> type <string> [nullable <boolean>])*) 

alter space <string> add index ( name <string> [type <string>] fields (<string> (, <string>)*)) 

alter space <string> drop index (<index_name> (, <index_name>)*)

Parameters

The following table describes the parameters for this command.

alter space Parameters
Parameter Description
space The name of the space to be modified.
add Specifies that a field is to be added:
  • name specifies the name of the field to be added.
  • type specifies the data type for the field. Must be one of the following: boolean, char, short, integer, long, float, double, string, datetime, blob.
  • nullable specifies whether the field is nullable. The nullable value is optional. The default for nullable is true.
  • encrypted  (optional) A boolean value specifying whether the field value is encrypted when it is stored in the space (default: false).
add index Specifies that an index is to be added:
  • name specifies the name of the index.
  • type specifies the type of the index, which can be hash or tree (default: tree).
  • fields specifies a comma-separated list of field names to be used in the index.
    Note: When you add an index, the new index cannot have fields from an existing index.
drop index Specifies that one or more indexes are to be removed.

The drop index option must be followed by a comma-separated list of one or more index names specifying the indexes to remove.

Examples

Examples for add field:

alter space “myspace” add (field name “average” type “double”)

alter space “myspace” add (field name “average” type “double” nullable true)

alter space “myspace” add (field name “average” type “double”, field name “total” type “long” nullable true)

Examples for add index:

alter space add index (name “index1” type “hash” fields(“a”, “b”, “c”))

alter space add index (name “index1” type “hash” fields(“a”, “b”, “c”)) index (name “index2” type “hash” fields(“a”, “b”, “c”))

Examples for drop index:

alter space drop index (“index1”)

alter space drop index (“index1”, “index2”)

Example for adding a field and an index:

alter space “myspace” add (field name “average” type “double”) index (name “index1” type “hash” fields(“a”, “b”, “c”))

The parameters for fields and index use the following format:

  • fields: (field name “average” type “double”)
  • index: index (name “index1” type “hash” fields(“a”, “b”, “c”))

You can perform consecutive updates by adding one field after another.