Data Types

GreptimeDB supports the following data types:

Type nameDescriptionAliasesSize
tinyint-128 ~ 127Int81 Byte
smallint-32768 ~ 32767Int162 Bytes
int-2147483648 ~ 2147483647Int324 Bytes
bigint-9223372036854775808 ~ 9223372036854775807Int648 Bytes
varcharUTF-8 encoded stringsText
/String
/ Char
The length of the strings
float32-bit IEEE754 floating point valuesFloat324 Bytes
doubleDouble precision IEEE 754 floating point valuesFloat648 Bytes
booleanbool valuesBoolean1 Byte
varbinaryVariable length binary valuesBinaryThe length of the data + 2 bytes
date32-bit date values represent the days since UNIX EpochDate4 Bytes
datetime64-bit datetime values represent the milliseconds since UNIX EpochDateTime8 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.
TimestampSecond
/TimestampMillisecond
/TimestampMicroSecond
/TimestampNanosecond
8 Bytes

Unsigned version of integer types

int / tinyint / smallint / bigint also have unsigned version, and there corresponding value ranges are:

  • int unsigned / UInt8 : 0 ~ 4294967295
  • tinyint unsigned / UInt16 : 0 ~ 255
  • smallint unsigned / UInt32 : 0 ~ 65535
  • bigint unsigned / UInt64 : 0 ~ 18446744073709551615

Variable-sized type limitations

The max capacities of variable-sized type, such as string and varbinary are determined by their encodings and how storage engine handles them.

For example, string values are encoded into UTF-8. If all characters are 3-bytes lengthed, this field can store 715827882 characters. As for varbinary types, it can store 2147483647 bytes at most.

Timestamp type alias

The timestamp type comes with various aliases, and it is suggested to use TimestampSecond, TimestampMillisecond, TimestampMicrosecond, and TimestampNanosecond.

The following table lists the corresponding alias.

Type nameAlias
TimestampSecondTimestamp_s, Timestamp_sec , Timestamp(0)
TimestampMillisecondTimestamp, Timestamp_ms , Timestamp(3)
TimestampMicrosecondTimestamp_us , Timestamp(6)
TimestampNanosecondTimestamp_ns , Timestamp(9)

Decimal

GreptimeDB supports decimal type, which is a fixed-point type.

It is represented as decimal(precision, scale), where precision is the total number of digits and scale is the number of digits in the fractional part. For example, 123.45 has a precision of 5 and a scale of 2.

  • precision can range from [1, 38].
  • scale can range from [0, precision].

The default decimal is decimal(38, 10) if the precision and scale are not specified.

Simple Usage

sql

  1. CREATE TABLE decimals(
  2. d DECIMAL(3, 2),
  3. ts TIMESTAMP TIME INDEX,
  4. );
  5. INSERT INTO decimals VALUES ('0.1',1000), ('0.2',2000);
  6. SELECT * FROM decimals;

Output:

sh

  1. +------+---------------------+
  2. | d | ts |
  3. +------+---------------------+
  4. | 0.10 | 1970-01-01T00:00:01 |
  5. | 0.20 | 1970-01-01T00:00:02 |
  6. +------+---------------------+

Examples

Create Table

sql

  1. CREATE TABLE data_types (
  2. s String,
  3. vbi Binary,
  4. b Boolean,
  5. tint Int8,
  6. sint Int16,
  7. i Int32,
  8. bint Int64,
  9. utint UInt8,
  10. usint UInt16,
  11. ui UInt32,
  12. ubint UInt64,
  13. f Float32,
  14. d Float64,
  15. dt Date,
  16. dtt DateTime,
  17. ts0 TimestampSecond,
  18. ts3 TimestampMillisecond,
  19. ts6 TimestampMicrosecond,
  20. ts9 TimestampNanosecond DEFAULT CURRENT_TIMESTAMP() TIME INDEX,
  21. PRIMARY KEY(s));

Describe Table

sh

  1. > describe table data_types;
  2. +--------+----------------------+------+------+---------------------+---------------+
  3. | Column | Type | Key | Null | Default | Semantic Type |
  4. +--------+----------------------+------+------+---------------------+---------------+
  5. | s | String | PRI | YES | | TAG |
  6. | vbi | Binary | | YES | | FIELD |
  7. | b | Boolean | | YES | | FIELD |
  8. | tint | Int8 | | YES | | FIELD |
  9. | sint | Int16 | | YES | | FIELD |
  10. | i | Int32 | | YES | | FIELD |
  11. | bint | Int64 | | YES | | FIELD |
  12. | utint | UInt8 | | YES | | FIELD |
  13. | usint | UInt16 | | YES | | FIELD |
  14. | ui | UInt32 | | YES | | FIELD |
  15. | ubint | UInt64 | | YES | | FIELD |
  16. | f | Float32 | | YES | | FIELD |
  17. | d | Float64 | | YES | | FIELD |
  18. | dt | Date | | YES | | FIELD |
  19. | dtt | DateTime | | YES | | FIELD |
  20. | ts0 | TimestampSecond | | YES | | FIELD |
  21. | ts3 | TimestampMillisecond | | YES | | FIELD |
  22. | ts6 | TimestampMicrosecond | | YES | | FIELD |
  23. | ts9 | TimestampNanosecond | PRI | NO | current_timestamp() | TIMESTAMP |
  24. +--------+----------------------+------+------+---------------------+---------------+