SQL infinity
Covers how infinite values arise and are tested: literals, arithmetic overflow to inf, and Oracle's IS INFINITE predicate.
- カテゴリ
- Math
- Returns
float / double- In this category
- 62 of 82
構文
'Infinity'::float8 -- PostgreSQL
IS INFINITE -- Oracle
9e999 -- SQLite inf
Each block is a separate form. The support table and the examples show which engine takes which.
エンジンサポート
| エンジン | Support | メモ |
|---|---|---|
| SQL Server | Not built in | No infinite float values: overflow raises an arithmetic overflow error instead |
| PostgreSQL | はい | 'Infinity' and '-Infinity' literals for float; '1e308'::float8 * 10 raises 'value out of range: overflow', so inf arrives via literals, casts or functions like cot(0) |
| MySQL | Not built in | No infinity: 1e308 * 10 raises 'DOUBLE value is out of range' |
| SQLite | Different name or syntax | 9e999 evaluates to Inf and stores fine; inf - inf gives NULL (NaN becomes NULL) |
| Oracle | はい | BINARY_DOUBLE_INFINITY literal and IS INFINITE / IS NOT INFINITE predicates |
例
PostgreSQL
SELECT 'Infinity'::float8 > 1e308 AS always_true; -- true
Oracle
SELECT * FROM t WHERE x IS INFINITE;
SQLite
SELECT 9e999 AS inf, 1e308 * 10 AS also_inf; -- Inf, Inf
知っておくと便利なこと
- PostgreSQL distinguishes overflow from literal infinity: 'Infinity'::float8 is fine, but '1e308'::float8 * 10 errors. A bare 1e308 * 10 is numeric there and simply returns a 309-digit number. Only SQLite and Oracle BINARY_DOUBLE (1e308d * 10) turn float overflow into Inf.
- Infinity compares greater than every finite number, and inf - inf is NaN (which SQLite then stores as NULL).
- Oracle's IS INFINITE is the only real predicate of the five. On PostgreSQL test x IN ('Infinity', '-Infinity'); on SQLite compare ABS(x) > 1.7976931348623157e308.
Questions about Infinity
Does 1e308 * 10 return Infinity in SQL?
Only on SQLite. MySQL and SQL Server raise an overflow error. PostgreSQL treats the literal as numeric and returns an exact 1 followed by 309 zeros; as float8 it raises an overflow error. Oracle NUMBER overflows (ORA-01426), while BINARY_DOUBLE gives Inf.
How do I test for infinity in SQL?
Oracle: x IS INFINITE. PostgreSQL: x IN ('Infinity'::float8, '-Infinity'::float8). SQLite: ABS(x) > 1.7976931348623157e308, since it has no predicate. SQL Server and MySQL never store infinity, so there is nothing to test.
What is Infinity minus Infinity?
NaN, under IEEE rules, and on SQLite that NaN immediately becomes NULL, so inf - inf returns NULL there.
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: PostgreSQL, 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.