Data types
Every column type Raft DB accepts in CREATE TABLE, with its range or length, its aliases, and the types it does not support yet.
A column has a type. Raft DB's SQL front-end keeps the type in the table definition, checks every value against it when it is stored (see Type conversion) and tells clients the type as MySQL or MariaDB would (so drivers and tools read the rows correctly). The values themselves are kept in Raft DB's JSON-native storage.
Types at a glance#
| Group | Types | Page |
|---|---|---|
| Whole numbers | TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, BOOL, SERIAL, UNSIGNED | Integer types |
| Exact and approximate numbers | DECIMAL(p,s), FLOAT, DOUBLE | DECIMAL, FLOAT and DOUBLE |
| Bits | BIT(M) | BIT type |
| Text | CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT | Character types |
| Bytes | BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB | Binary types |
| Lists | ENUM, SET | ENUM and SET |
| Dates and times | DATE, DATETIME(n), TIMESTAMP(n), TIME(n), YEAR | Date and time types |
| Documents | JSON | JSON type |
| MariaDB types | UUID, INET4, INET6 | UUID, INET4 and INET6 |
Syntax#
column_name type [(length [, decimals])] [UNSIGNED | SIGNED | ZEROFILL]
[CHARACTER SET name] [COLLATE name]
[NOT NULL | NULL] [DEFAULT value | DEFAULT (expr)] [AUTO_INCREMENT]
[UNIQUE [KEY]] [PRIMARY KEY] [COMMENT 'text'] [INVISIBLE]
[GENERATED ALWAYS AS (expr) [VIRTUAL | STORED]]The statements that define columns are on CREATE TABLE and ALTER TABLE.
Aliases#
An alias is read as the type it stands for. SHOW CREATE TABLE and DESCRIBE show the type it stands for.
| Alias | Type |
|---|---|
INTEGER, INT4 | INT |
INT1 | TINYINT |
INT2 | SMALLINT |
INT3, MIDDLEINT | MEDIUMINT |
INT8 | BIGINT |
BOOL, BOOLEAN | TINYINT(1) |
NUMERIC, DEC, FIXED | DECIMAL |
REAL, DOUBLE PRECISION, FLOAT8 | DOUBLE |
FLOAT4 | FLOAT |
CHARACTER | CHAR |
CHAR VARYING, CHARACTER VARYING, VARCHARACTER, NVARCHAR, NCHAR VARCHAR, NATIONAL VARCHAR, NATIONAL CHAR VARYING | VARCHAR |
NCHAR, NATIONAL CHAR | CHAR |
CHAR BYTE | BINARY |
LONG, LONG VARCHAR, LONG CHAR VARYING | MEDIUMTEXT |
LONG VARBINARY | MEDIUMBLOB |
SERIAL | BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE |
VARCHAR2, CLOB, RAW, NUMBER (the names of MariaDB's Oracle mode) | VARCHAR, LONGTEXT, VARBINARY, DECIMAL |
The aliases that come from MariaDB's list (FLOAT4, FLOAT8, LONG ..., CHAR VARYING and so on) are read in both dialects. A national type does not get its own character set: it is utf8mb4 like the others.
Remarks#
- Width. The number in
INT(11)is a display width: it is read, kept and, in the MariaDB dialect, shown (int(11); MySQL 8 showsint). It does not change the range. ZEROFILLis accepted and ignored.SIGNEDis accepted.- Limits.
DECIMAL: up to 65 digits, up to 30 decimals.BIT: 1 to 64 bits.DATETIME,TIMESTAMP,TIME: up to 6 fractional digits. A length outside the limits is an error as in the servers: error 1426Too-big precision ... Maximum is 6(fractional digits) orMaximum is 65(DECIMAL; MariaDB words itPrecision given for 'x' is too big; the largest allowed is 65), error 1439 for aBITwider than 64. - Not supported yet (the statement is refused with error 1235,
This version of the Raft DB MySQL front-end doesn't yet support 'the column type X'):ROW,TYPE OF, and the other types of MariaDB's Oracle mode. - Spatial types (D106):
GEOMETRY,POINT,LINESTRING,POLYGON,MULTIPOINT,MULTILINESTRING,MULTIPOLYGON,GEOMETRYCOLLECTION(MySQL showsgeomcollection). A value is the servers' internal format (4-byte SRID and WKB) and reaches clients as a binaryGEOMETRYcolumn.SRID nafter the type (MySQL). See spatial functions. VECTOR(n)(MySQL 9 only; MariaDB 11.4 has no such type and answers error 4161): single-precision floats, up to 16383 dimensions, made withSTRING_TO_VECTOR('[1,2,3]')and shown withVECTOR_TO_STRING.- Partition and
FULLTEXTkeys in the definition are accepted and not kept;SPATIALkeys are kept as definitions (listed bySHOW CREATE TABLE, no structure). SHOW COLUMNSandinformation_schema.COLUMNSdescribe each column withCOLUMN_TYPE,DATA_TYPE, the lengths and the precisions the servers give.
Examples#
CREATE TABLE types (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
ti TINYINT, si SMALLINT, mi MEDIUMINT, bi BIGINT,
u8 TINYINT UNSIGNED,
f FLOAT, d DOUBLE, p DECIMAL(8,3),
c CHAR(5), v VARCHAR(10), t TEXT,
dt DATE, ts DATETIME, tm TIME, y YEAR,
j JSON,
b BOOLEAN
);
DESCRIBE types;
SHOW CREATE TABLE types;
```7.
## See also
* [Type conversion](/docs/sql-reference/type-conversion)
* [SQL modes](/docs/sql-reference/sql-modes)
* [CREATE TABLE statement](/docs/sql-reference/create-table)