SQL reference (MySQL and MariaDB dialects)

Binary types

BINARY, VARBINARY and the BLOB family: how Raft DB stores them, the UTF-8 limit and how they differ from MySQL and MariaDB.

Syntax#

SQL
BINARY [(length)]
VARBINARY (length)
TINYBLOB | BLOB | MEDIUMBLOB | LONGBLOB

Limits#

TypeLength
BINARY(n)n bytes, default 1
VARBINARY(n)n bytes
TINYBLOB255
BLOB65,535
MEDIUMBLOB16,777,215
LONGBLOB4,294,967,295

Remarks#

  • The bytes must be valid UTF-8. Raft DB keeps these columns as text with the flags of a binary column (clients see the binary character set, 63, so a VARBINARY is read as bytes by drivers). A value that is not valid UTF-8 cannot be stored yet: a statement that is not UTF-8 text is refused with error 1366 instead of being changed on its way in. True binary values need the engine's value type to carry bytes, which is a later change.
  • BINARY(n) is not padded. MySQL pads a BINARY(n) value with zero bytes to n; Raft DB does not.
  • Comparison ignores case for these types as for text (real MySQL compares bytes). BINARY 'a' = 'A' is 1 here and 0 in MySQL.
  • Hexadecimal literals (0x41, X'41') and _binary 'x' give bytes; see Literals. HEX, UNHEX, TO_BASE64 and FROM_BASE64 work on the text of the value (UNHEX and FROM_BASE64 return text when the bytes are valid UTF-8).
  • Aliases. LONG VARBINARY is MEDIUMBLOB, RAW (Oracle mode) is VARBINARY, CHAR BYTE is BINARY.
  • Too long: error 1406 in strict mode; cut with a warning otherwise.

Examples#

SQL
CREATE TABLE b (k BINARY(4), v VARBINARY(16), d BLOB);
INSERT INTO b VALUES ('abcd', 'hello', 'a longer value');
SELECT HEX(v), LENGTH(d) FROM b;

See also#