CREATE TABLE
Create a table with the specified data schema and PRIMARY KEY
(key column):
CREATE TABLE table_name (
column1 type1,
column2 type2,
...
columnN typeN,
PRIMARY KEY (column, ...)
)
For the key and non-key columns, you can only use primitive data types.
It is mandatory to specify the PRIMARY KEY
with a non-empty list of columns. Those columns become part of the key in the listed order.
Example
CREATE TABLE my_table (
a Uint64,
b Bool,
c Float,
PRIMARY KEY (b, a)
)
Adding secondary indexes
To add a secondary index when creating a table, use the statement INDEX IndexName GLOBAL on (SomeKey1, ... SomeKeyN)
:
CREATE TABLE TableName (
Key1 Type,
Key2 Type,
…
PRIMARY KEY (SomeKey),
INDEX IndexName1 GLOBAL ON (SomeKey),
INDEX IndexName2 GLOBAL ON (SomeKey1, SomeKey2, ...)
);
COMMIT;
Example
The series
table with the views_index
secondary index for the views
field and users_index
secondary index for the uploaded_user_id
field:
CREATE TABLE series (
series_id Uint64,
title Utf8,
info Utf8,
release_date Datetime,
views Uint64,
uploaded_user_id Uint64,
PRIMARY KEY (series_id),
INDEX views_index GLOBAL ON (views),
INDEX users_index GLOBAL ON (uploaded_user_id)
);