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#
BINARY [(length)]
VARBINARY (length)
TINYBLOB | BLOB | MEDIUMBLOB | LONGBLOBLimits#
| Type | Length |
|---|---|
BINARY(n) | n bytes, default 1 |
VARBINARY(n) | n bytes |
TINYBLOB | 255 |
BLOB | 65,535 |
MEDIUMBLOB | 16,777,215 |
LONGBLOB | 4,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
VARBINARYis 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 aBINARY(n)value with zero bytes ton; 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_BASE64andFROM_BASE64work on the text of the value (UNHEXandFROM_BASE64return text when the bytes are valid UTF-8). - Aliases.
LONG VARBINARYisMEDIUMBLOB,RAW(Oracle mode) isVARBINARY,CHAR BYTEisBINARY. - Too long: error 1406 in strict mode; cut with a warning otherwise.
Examples#
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;