SQL reference (MySQL and MariaDB dialects)

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#

GroupTypesPage
Whole numbersTINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, BOOL, SERIAL, UNSIGNEDInteger types
Exact and approximate numbersDECIMAL(p,s), FLOAT, DOUBLEDECIMAL, FLOAT and DOUBLE
BitsBIT(M)BIT type
TextCHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXTCharacter types
BytesBINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOBBinary types
ListsENUM, SETENUM and SET
Dates and timesDATE, DATETIME(n), TIMESTAMP(n), TIME(n), YEARDate and time types
DocumentsJSONJSON type
MariaDB typesUUID, INET4, INET6UUID, INET4 and INET6

Syntax#

SQL
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.

AliasType
INTEGER, INT4INT
INT1TINYINT
INT2SMALLINT
INT3, MIDDLEINTMEDIUMINT
INT8BIGINT
BOOL, BOOLEANTINYINT(1)
NUMERIC, DEC, FIXEDDECIMAL
REAL, DOUBLE PRECISION, FLOAT8DOUBLE
FLOAT4FLOAT
CHARACTERCHAR
CHAR VARYING, CHARACTER VARYING, VARCHARACTER, NVARCHAR, NCHAR VARCHAR, NATIONAL VARCHAR, NATIONAL CHAR VARYINGVARCHAR
NCHAR, NATIONAL CHARCHAR
CHAR BYTEBINARY
LONG, LONG VARCHAR, LONG CHAR VARYINGMEDIUMTEXT
LONG VARBINARYMEDIUMBLOB
SERIALBIGINT 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 shows int). It does not change the range.
  • ZEROFILL is accepted and ignored. SIGNED is 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 1426 Too-big precision ... Maximum is 6 (fractional digits) or Maximum is 65 (DECIMAL; MariaDB words it Precision given for 'x' is too big; the largest allowed is 65), error 1439 for a BIT wider 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 shows geomcollection). A value is the servers' internal format (4-byte SRID and WKB) and reaches clients as a binary GEOMETRY column. SRID n after 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 with STRING_TO_VECTOR('[1,2,3]') and shown with VECTOR_TO_STRING.
  • Partition and FULLTEXT keys in the definition are accepted and not kept; SPATIAL keys are kept as definitions (listed by SHOW CREATE TABLE, no structure).
  • SHOW COLUMNS and information_schema.COLUMNS describe each column with COLUMN_TYPE, DATA_TYPE, the lengths and the precisions the servers give.

Examples#

SQL
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)