BIT
One-byte flags in SQL Server, bit strings elsewhere, integers in the rest.
- Family
- Exact decimals
- Missing in
- SQLite, Oracle
- Gotchas
- 4 listed
Engine by engine
SQL Server packs up to 8 BIT columns per byte; PostgreSQL and MySQL have real bit-string types; SQLite and Oracle make do with integers.
| 引擎 | 類型 | 儲存 | 備註 |
|---|---|---|---|
| SQL Server |
BIT
|
1 byte (up to 8 packed) | Stores 0, 1 or NULL; adjacent BIT columns in the same table share bytes, so 8 flags cost 1 byte total. |
| PostgreSQL |
BIT(n) / BIT VARYING(n)
|
(n+7)/8 bytes + overhead | Fixed- or variable-length bit strings - not a boolean. Use the BOOLEAN type for flags. |
| MySQL |
BIT(M), M = 1-64
|
(M+7)/8 bytes | Values are binary literals such as b'101'; many drivers return raw byte arrays. |
| SQLite |
no BIT - use INTEGER
Workaround
|
up to 8 bytes | Flags are INTEGER 0/1; a bitmask INTEGER works when packing is wanted. |
| Oracle |
no BIT - use BOOLEAN, NUMBER(1) or RAW
Workaround
|
1-2 bytes / variable | Flags: BOOLEAN from 23ai, NUMBER(1) plus a CHECK before that; bit masks: RAW or NUMBER with BITAND(). |
Gotchas
Where the engines disagree. These tend to surface as bugs during a migration or a port.
- MySQL's BIT often arrives in application code as a byte array, so bit_col = 1 checks fail; return CAST(bit_col AS UNSIGNED) or prefer TINYINT(1).
- SQL Server packs up to 8 BIT columns into 1 byte, but a lone BIT still costs 1 byte, and a nullable BIT has three states: WHERE flag <> 1 skips the NULL rows.
- PostgreSQL's BIT(n) is a bit-string type for masks and fingerprints, not a flag: BIT(1) compares against B'1', not 1 or TRUE. Use BOOLEAN for true/false.
- SQLite accepts BIT as a type name but applies NUMERIC affinity: 0 and 1 store as integers, and a stray 'flag' string silently corrupts the column.
Common questions
Is BIT a boolean?
In SQL Server, practically yes (0/1/NULL). In MySQL and PostgreSQL it is a bit field or bit string; for true/false prefer each engine's boolean or TINYINT(1).
How big is a SQL Server BIT column?
1 byte when it stands alone; up to 8 BIT columns in the same table share a single byte.
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.