SQL DOUBLE PRECISION
Explains the binary double format behind FLOAT/REAL/DOUBLE PRECISION: its digit budget, its special values, and which engines map which names onto it.
- 類別
- Math
- Returns
8-byte IEEE 754 float- In this category
- 66 of 82
語法
DOUBLE PRECISION
FLOAT
BINARY_DOUBLE -- Oracle
Each block is a separate form. The support table and the examples show which engine takes which.
引擎支援
| 引擎 | Support | 備註 |
|---|---|---|
| SQL Server | 是 | FLOAT in T-SQL defaults to FLOAT(53), a full IEEE double; REAL is the 4-byte single |
| PostgreSQL | 是 | double precision (float8) is the 8-byte IEEE double; real (float4) is single |
| MySQL | 是 | DOUBLE and FLOAT are distinct 8- and 4-byte IEEE types |
| SQLite | 是 | REAL is the only floating type: an 8-byte IEEE double |
| Oracle | 是 | BINARY_DOUBLE is the IEEE double; DOUBLE PRECISION is FLOAT(126), a decimal NUMBER subtype |
範例
SQL Server
SELECT 0.1e0 + 0.2e0 AS binary_sum; -- 0.30000000000000004 (e-notation is FLOAT)
PostgreSQL
SELECT 0.1::float8 + 0.2::float8 AS binary_sum; -- 0.30000000000000004
Oracle
SELECT CAST(1.5 AS BINARY_DOUBLE) AS true_double FROM dual;
SQL Server
SELECT CAST(1e308 AS FLOAT) * 10 AS overflow_attempt; -- Msg 8115 arithmetic overflow, not Inf
小知識
- 15 to 17 significant digits, 0.1-style decimals never exact, values past 1.8e308 overflow. Everything about float arithmetic follows from those three facts.
- Names mislead: Oracle's DOUBLE PRECISION is a decimal NUMBER (FLOAT(126)), not IEEE, unless you declare BINARY_DOUBLE. SQL Server's FLOAT is already a double, and MySQL's FLOAT is the 4-byte single.
- IEEE doubles define NaN and Infinity, but engine storage decides whether you can keep them: PostgreSQL and Oracle binary types yes, SQLite keeps Inf and turns NaN into NULL, SQL Server and MySQL never.
Questions about DOUBLE PRECISION
How many digits can a DOUBLE hold?
About 15 to 17 significant decimal digits (IEEE 754 binary64). Past that, digits are lost: 1234567890123456789 stored as a double comes back with trailing digits changed.
Is SQL Server's FLOAT a single or double?
A double: FLOAT defaults to FLOAT(53), the full 8-byte IEEE binary64. REAL is the 4-byte single precision type.
Why does Oracle's DOUBLE PRECISION not support NaN?
Oracle implements DOUBLE PRECISION as FLOAT(126), a subtype of its decimal NUMBER, which has no IEEE special values. Declare BINARY_DOUBLE to get true IEEE semantics including NaN and Infinity.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.