Skip to content

CREATE SHARDING KEY GENERATOR

Description

The CREATE SHARDING KEY GENERATOR syntax is used to create an independent sharding key generator for the currently selected database.

Syntax

CreateShardingKeyGenerator ::=
  'CREATE' 'SHARDING' 'KEY' 'GENERATOR' ifNotExists? keyGeneratorName '(' algorithmDefinition ')'

ifNotExists ::=
  'IF' 'NOT' 'EXISTS'

algorithmDefinition ::=
  'TYPE' '(' 'NAME' '=' algorithmType (',' propertiesDefinition)? ')'

propertiesDefinition ::=
  'PROPERTIES' '(' (key '=' value (',' key '=' value)*)? ')'

key ::=
  string

value ::=
  literal

keyGeneratorName ::=
  identifier

algorithmType ::=
  string

Supplement

  • keyGeneratorName is the name of the independent sharding key generator;
  • algorithmDefinition defines the key generator algorithm and its properties;
  • algorithmType is the key generation algorithm type. For details, refer to Distributed Primary Key;
  • ifNotExists clause is used to avoid Duplicate sharding key generator error.

Example

  • Create a sharding key generator
CREATE SHARDING KEY GENERATOR snowflake_generator (
TYPE(NAME="SNOWFLAKE",PROPERTIES("worker-id"=1))
);
  • Create a sharding key generator with ifNotExists clause
CREATE SHARDING KEY GENERATOR IF NOT EXISTS snowflake_generator (
TYPE(NAME="SNOWFLAKE")
);

Reserved word

CREATE, SHARDING, KEY, GENERATOR, IF, NOT, EXISTS, TYPE, NAME, PROPERTIES

Related links