DDL - Tables
CREATE TABLE
CREATE TABLE [IF NOT EXISTS] <table>
(<column> <type> [NOT NULL] [ENCODING <encodingSpec>],
[SHARD KEY (<column>)],
[SHARED DICTIONARY (<column>) REFERENCES <table>(<column>)], ...)
[WITH (<property> = value, ...)];
Create a table named <table>
specifying <columns>
and table properties.
<type>
Supported types:
Datatype | Size (bytes) | Notes |
---|---|---|
TEXT ENCODING DICT |
4 | Max cardinality 1 billion distinct string values |
TEXT ENCODING NONE |
Variable | Size of the string + 6 bytes |
TIMESTAMP |
8 | |
TIME |
8 | |
DATE |
8 | |
FLOAT |
4 | |
DOUBLE |
8 | |
INTEGER |
4 | |
TINYINT |
1 | |
SMALLINT |
2 | |
BIGINT |
8 | |
BOOLEAN |
1 | |
DECIMAL/NUMERIC |
8 |
For more information, see Datatypes and Fixed Encoding.
Example
Create a table named tweets
and specify the columns, including type, in the table.
CREATE TABLE IF NOT EXISTS tweets (
tweet_id BIGINT NOT NULL,
tweet_time TIMESTAMP NOT NULL ENCODING FIXED(32),
lat REAL,
lon REAL,
sender_id BIGINT NOT NULL,
sender_name TEXT NOT NULL ENCODING DICT,
location TEXT ENCODING DICT,
source TEXT ENCODING DICT,
reply_to_user_id BIGINT,
reply_to_tweet_id BIGINT,
lang TEXT ENCODING DICT,
followers INT,
followees INT,
tweet_count INT,
join_time TIMESTAMP ENCODING FIXED(32),
tweet_text TEXT,
state TEXT ENCODING DICT,
county TEXT ENCODING DICT,
place_name TEXT,
state_abbr TEXT ENCODING DICT,
county_state TEXT ENCODING DICT,
origin TEXT ENCODING DICT);