// data type reference

CHAR(n)

Fixed-length, space-padded strings - and what each engine does with the padding.

Family
텍스트
Missing in
None of the five
Gotchas
4 listed

Engine by engine

CHAR(n) pads to n and every engine cleans up the padding differently; SQLite ignores the whole idea and Oracle counts bytes.

CHAR(n) in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
엔진 타입 저장소 메모
SQL Server CHAR(n) n bytes, 1-8000 Blank-padded on storage; = and LIKE both ignore the stored padding, but trailing spaces inside a LIKE pattern count.
PostgreSQL CHAR(n) (character(n)) n chars + small overhead Padded to n characters; casts and most comparisons strip the padding.
MySQL CHAR(n) n chars x charset bytes utf8mb4 reserves up to 4 bytes per character; retrieval strips trailing spaces (VARCHAR keeps them).
SQLite CHAR(n) (TEXT affinity) variable No padding and no length enforcement: anything non-TEXT is coerced and n is ignored.
Oracle CHAR(n) / NCHAR(n) n bytes or n chars, max 2000 BYTE semantics by default; CHAR semantics via CHAR(n CHAR) or NLS_LENGTH_SEMANTICS.

Gotchas

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

  1. CHAR(n) pads values shorter than n, and engines disagree on cleanup: MySQL strips padding on retrieval, PostgreSQL strips it on cast to text, SQL Server and Oracle return it padded and ignore it in = comparisons.
  2. SQLite accepts CHAR(n) as TEXT affinity and never enforces n or pads - a schema port that silently changes semantics.
  3. Oracle sizes CHAR in bytes by default: in AL32UTF8 a CJK character takes 3 bytes, so CHAR(10) rejects a 4-character Japanese value. Declare CHAR(n CHAR) instead.
  4. VARCHAR(n) is almost always the better default today; CHAR earns its keep only for truly fixed codes like country and currency.

Common questions

Does CHAR save space over VARCHAR?

Rarely. Variable-length storage costs only a 1-2 byte length prefix, and with multi-byte character sets CHAR is not even fixed-size on disk. The PostgreSQL docs call character(n) the slowest of its three string types.

Why do trailing spaces disappear from CHAR columns?

Because every engine handles the padding differently: MySQL strips it on retrieval, PostgreSQL strips it on cast to text, and SQL Server and Oracle keep it but ignore it in = comparisons.

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