Appropriate values for -Infinity & Infinity in Postgres Appropriate values for -Infinity & Infinity in Postgres sql sql

Appropriate values for -Infinity & Infinity in Postgres


You can actually use +infinity and -infinity for FLOAT4 and FLOAT8 (i.e. float and double precision) data types, and for timestamps.

regress=> SELECT FLOAT8 '+infinity', FLOAT8 '-infinity';  float8  |  float8   ----------+----------- Infinity | -Infinity(1 row)

For other types, either use a separate column, use the minimum/maximum values for the type, or (where logically appropriate) use null.


add another column name "infinite", 1 means +infinity, -1 means -infinitywhen you are checking numbers, check the column first.

this will save you a lot of time thinking about magic numbers or other stuff.