// data type reference

Emulating BOOLEAN with BIT, TINYINT(1) and CHAR(1)

Where BOOLEAN does not exist, schemas invent one: a BIT, a TINYINT(1), a CHAR(1) holding Y or N. Each emulation needs a CHECK constraint to behave like a boolean.

Missing in
None of the five
Gotchas
5 listed

Engine by engine

The portable pattern is an integer 0/1 with a CHECK (col IN (0, 1)) constraint. SQL Server's BIT constrains itself; CHAR(1) Y/N is app-specific and the least portable choice.

Boolean emulation in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
Engine Typ Speicher Notizen
SQL Server BIT 1 byte BIT already restricts values to 0, 1 and NULL, so no CHECK is needed; comparisons write col = 1, never col = TRUE.
PostgreSQL BOOLEAN 1 byte Native type - no emulation needed on this engine.
MySQL TINYINT(1) 1 byte Declare BOOLEAN, then add CHECK (col IN (0, 1)) (enforced from 8.0.16) to keep out 2s and 42s.
SQLite INTEGER 1 to 8 bytes SQLite stores any integer, so CHECK (col IN (0, 1)) is what makes the convention binding; TRUE and FALSE keywords map to 1 and 0.
Oracle NUMBER(1) 1-2 bytes Pre-23ai pattern: NUMBER(1) with 0/1, or CHAR(1) with 'Y'/'N'; pick one convention app-wide and CHECK it. 23ai has a real BOOLEAN.

Gotchas

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

  1. CHAR(1) 'Y'/'N' is the least portable emulation: every engine, driver and ORM needs custom mapping, and mixing it with 0/1 columns in one schema is a classic source of bugs.
  2. NULL is a third state. WHERE deleted = 0 excludes NULL rows, so 'not deleted' silently loses records unless the column is NOT NULL or the predicate says deleted = 0 OR deleted IS NULL.
  3. Without a CHECK constraint, MySQL and SQLite accept any integer: 2, -1, 255. The type name BOOLEAN in MySQL enforces nothing.
  4. Comparing against TRUE is fragile on emulators: in MySQL, a flag holding 2 passes WHERE flag and flag IS TRUE but fails flag = TRUE (TRUE is just 1). SQL Server has no TRUE literal, and CHAR(1) Y/N columns match neither.
  5. ORMs differ on mapping: some render BIT/TINYINT as true/false, others as numbers, so the same column reads differently depending on which client asks.

Common questions

What is the most portable way to emulate BOOLEAN?

An integer column with values 0 and 1 plus CHECK (col IN (0, 1)), and NOT NULL when the tri-state is not wanted. It maps cleanly in every engine and driver.

Should I use CHAR(1) 'Y'/'N' for booleans?

Only if an existing standard forces it. It is app-specific, needs custom mapping in every client, and mixes badly with 0/1 columns elsewhere in the schema.

Why do my MySQL boolean checks return unexpected rows?

Because the column has no CHECK constraint, so values like 2 get in: WHERE flag matches them, WHERE flag = TRUE does not. Add CHECK (col IN (0, 1)) and make the column NOT NULL.

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