// data type reference

BINARY and VARBINARY

Short byte strings - hashes, UUIDs, tokens - belong in a binary type. The names are close across engines, but padding rules and size ceilings differ in ways that bite.

Missing in
None of the five
Gotchas
5 listed

Engine by engine

Fixed-length BINARY pads with zero bytes; variable-length types (VARBINARY, BYTEA, RAW) do not. Ceilings range from 2,000 bytes (Oracle RAW) to 65,535 (MySQL row limit).

BINARY and VARBINARY in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
Engine Type Storage Notes
SQL Server BINARY(n) / VARBINARY(n) n / n + 2 bytes BINARY pads to n with 0x00; n maxes at 8000, and VARBINARY(MAX) reaches 2 GB.
PostgreSQL BYTEA n + 1 or 4 bytes Variable length with a 1-byte header up to 126 bytes, 4 bytes above; no fixed-length binary type, so no padding.
MySQL BINARY(n) / VARBINARY(n) n / n + 1-2 bytes BINARY pads with 0x00; both are capped by the 65,535-byte row size, n included in that budget.
SQLite BLOB n bytes One type for all sizes; values are written with X'...' hex literals and compare byte by byte.
Oracle RAW(n) n bytes Inline variable-length bytes, n up to 2000 (32,767 with MAX_STRING_SIZE = EXTENDED); hex input and output by default.

Gotchas

Where the engines disagree. These tend to surface as bugs during a migration or a port.

  1. Fixed-length BINARY pads with 0x00 in SQL Server and MySQL, but comparisons differ: SQL Server ignores trailing zeros (0x01 = 0x0100 is true, even for VARBINARY), while in MySQL a BINARY(3) holding 'a' no longer equals 'a'.
  2. PostgreSQL has no fixed-length binary type. BYTEA never pads, so porting a BINARY(n) column needs a CHECK (octet_length = n) to keep the contract.
  3. MySQL counts binary columns against the 65,535-byte row limit: three VARBINARY(30000) columns fail CREATE TABLE with error 1118. Switch large ones to BLOB, which counts only 9-12 bytes.
  4. Oracle RAW tops out at 2,000 bytes (32767 in extended mode). Anything bigger must be a BLOB, which changes the API to LOB operations.
  5. SQLite's BLOB has one type for every purpose and no length check: a 32-byte hash column accepts a 1 GB value unless a CHECK (length(col) = 32) says otherwise.

Common questions

What is the difference between BINARY and VARBINARY?

BINARY(n) is fixed-length and pads with 0x00 to exactly n bytes; VARBINARY(n) stores only the bytes given plus a length. Use BINARY for fixed-size values like SHA-256 digests.

How many bytes can VARBINARY hold?

SQL Server: 8,000 inline or 2 GB with MAX. MySQL: 65,535 minus the rest of the row. PostgreSQL BYTEA: about 1 GB. Oracle RAW: 2,000 (or 32,767 extended). SQLite BLOB: 1 billion bytes by default.

What does PostgreSQL use instead of VARBINARY?

BYTEA. It is always variable-length, stores n bytes plus a 1- or 4-byte header, and reads and writes hex like '\x9401' by default.

// map types before you move data

Map a type to the other four engines

The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.