FLOAT(p)
FLOAT(p) looks like one type with a precision knob. In SQL Server, PostgreSQL and MySQL it picks a 4- or 8-byte IEEE float; in Oracle the same keyword declares a decimal NUMBER.
- Family
- Approximate numbers
- Missing in
- None of the five
- Gotchas
- 5 listed
Engine by engine
SQL standard FLOAT(p): p up to 24 selects a 4-byte IEEE float, 25 to 53 an 8-byte double - except Oracle, where FLOAT(p) is decimal NUMBER and BINARY_FLOAT is the real float.
| エンジン | 型 | ストレージ | メモ |
|---|---|---|---|
| SQL Server |
FLOAT(p)
|
4 or 8 bytes | p 1-24 is 4 bytes, p 25-53 is 8 bytes. REAL is a synonym for FLOAT(24); the default FLOAT is FLOAT(53). |
| PostgreSQL |
float(p)
|
4 or 8 bytes | p 1-24 selects real (4 bytes), p 25-53 selects double precision (8 bytes); the precision is advisory, not exact digits. |
| MySQL |
FLOAT(p)
|
4 or 8 bytes | p 0-24 maps to FLOAT, 25-53 to DOUBLE. FLOAT(p) is fine; the two-argument FLOAT(M,D) form is the deprecated one. |
| SQLite |
REAL
|
8 bytes | One IEEE 754 double for every floating-point column; the declared precision is ignored entirely. |
| Oracle |
FLOAT(p)
|
1-21 bytes (decimal) | Not IEEE: FLOAT(p) is a NUMBER subtype whose precision p (1-126) counts binary digits, about 0.3 x p decimal digits. The 4-byte IEEE float is BINARY_FLOAT. |
Gotchas
Where the engines disagree. These tend to surface as bugs during a migration or a port.
- Oracle's FLOAT(p) is the trap: it is a decimal NUMBER subtype, not IEEE 754, so FLOAT(24) gives about 7 decimal digits of NUMBER, not a 4-byte float. Code that expects IEEE rounding and NaN needs BINARY_FLOAT or BINARY_DOUBLE.
- The 24/25 boundary decides storage: p up to 24 gives a 4-byte single, 25 and up an 8-byte double, in SQL Server, PostgreSQL and MySQL alike.
- MySQL deprecates FLOAT(M,D) and DOUBLE(M,D) (the two-argument display forms) since 8.0.17; single-argument FLOAT(p) is standard SQL and still fine.
- SQLite ignores declared precision: FLOAT(10) and DOUBLE PRECISION both become the same 8-byte REAL.
- Approximate types never store exact decimals: 0.1 drifts, equality comparisons fail, and money in FLOAT is a bug waiting to be filed.
Common questions
Is FLOAT(p) exact?
Not in SQL Server, PostgreSQL, MySQL or SQLite: there it is binary floating point, 0.1 has no exact form, and sums drift. Oracle is the odd one out, since its FLOAT(p) is a decimal NUMBER. Use NUMERIC for exact decimals.
What is Oracle's equivalent of an IEEE float?
BINARY_FLOAT (4 bytes) and BINARY_DOUBLE (8 bytes). Oracle's FLOAT(p) is a decimal NUMBER subtype with binary precision p, so it rounds like NUMBER, not like IEEE.
How many bytes is FLOAT(p)?
4 bytes when p is 24 or below, 8 bytes when p is 25 to 53, in SQL Server, PostgreSQL and MySQL. SQLite always uses 8 bytes; Oracle's FLOAT is variable-length decimal.
Related on SQLly
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.