数据类型

GreptimeDB 支持下列数据类型:

Type nameDescriptionSynonymsSize
tinyint8-bit signed small integers between -128~1271 Byte
smallint16-bit signed big integers between -32768~327672 Bytes
int32-bit signed integers between -2147483648~2147483647integer4 Bytes
bigint64-bit signed big integers between -9223372036854775808~92233720368547758078 Bytes
varcharUTF-8 encoded stringstext
/string
/ char
The length of the strings
float32-bit IEEE754 floating point values4 Bytes
doubleDouble precision IEEE 754 floating point values8 Bytes
booleanBoolean values1 Byte
varbinaryVariable length binary valuesThe length of the data + 2 bytes
date32-bit date values4 Bytes
datetime64-bit datetime values8 Bytes
timestamp[(0/3/6/9)]64-bit timestamp values with optional precision.
For example, timestamp(0) represents timestamp type with seconds precision, timestamp(3) represents milliseconds precision, timestamp(6) for microseonds and timestamp(9) for nanoseconds. If no precision is given, the timestamp is in milliseconds precision by default.
8 Bytes

整数类型的 Unsigned 版本

int / tinyint / smallint / bigint 有 unsigned 版本,相应的值范围如下:

  • int unsigned: 0~4294967295
  • tinyint unsigned: 0~255
  • smallint unsigned: 0~65535
  • bigint unsigned: 0~18446744073709551615

Variable-sized 类型的限制

variable-sized 类型的最大容量, 例如 stringvarbinary,取决于它们的编码和存储引擎处理它们的方式。

例如,string 值被编码为 UTF-8。如果所有字符都是 3 字节长度,则该字段可以存储 715827882 个字符。对于 varbinary 类型,最多可以存储 2147483647 字节。

为 timestamp 列选择数据类型

GreptimeDB 允许用户为时间戳索引列设置为 biginttimestamp 类型。 biginttimestamp 都被解释为毫秒精度的时间戳。

sql

  1. # using TIMESTAMP as timestamp column data type
  2. CREATE TABLE monitor (
  3. host STRING,
  4. ts TIMESTAMP,
  5. cpu DOUBLE DEFAULT 0,
  6. memory DOUBLE,
  7. TIME INDEX (ts),
  8. PRIMARY KEY(host)) ENGINE=mito WITH(regions=1);
  9. # using BIGINT as timestamp column data type is also allowed
  10. CREATE TABLE monitor (
  11. host STRING,
  12. ts BIGINT,
  13. cpu DOUBLE DEFAULT 0,
  14. memory DOUBLE,
  15. TIME INDEX (ts),
  16. PRIMARY KEY(host)) ENGINE=mito WITH(regions=1);