MySQL and Negative Infinity

Examples

mysql

Storing and retrieving negative infinity in a MySQL database is accomplished by inserting an arbitrarily large negative number.  Negative infinity is handy when storing default values in a database.

The following SQL statement is an example of inserting negative infinity:

INSERT INTO test(negative_infinity) VALUES('-1e500');

Here is the test table:

CREATE TABLE test (
     negative_infinity DOUBLE NOT NULL
) ENGINE=INNODB character set utf8;

The value in the database is stored as the maximum negative value for the data type, double (-1.79769313486232e+308).

mysql> select * from test;
+------------------------+
| negative_infinity      |
+------------------------+
| -1.79769313486232e+308 |
+------------------------+
1 row in set (0.00 sec)

In Java, the Double contsant for max infinity, directly correlates to the value stored by MySQL.

No Comments

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>