MySQL NULL gotcha; or, yes, Virginia, types do matter

| | Comments (0) | TrackBacks (0)

If you spend a lot of time dealing with languages that are loosely typed and have scalars running wild, then like me, you may be prone to doing something like this:

mysql> select NOW(); select GREATEST(NOW(), DATE_ADD(NOW(),INTERVAL 1 DAY)); +---------------------+ | NOW() | +---------------------+ | 2009-04-28 14:17:36 | +---------------------+ 1 row in set (0.00 sec)

+-------------------------------------------------+
| GREATEST(NOW(), DATE_ADD(NOW(),INTERVAL 1 DAY)) |
+-------------------------------------------------+
| 2009-04-29 14:17:36 |
+-------------------------------------------------+
1 row in set (0.00 sec)

mysql> select GREATEST(NULL, NOW());
+-----------------------+
| GREATEST(NULL, NOW()) |
+-----------------------+
| NULL |
+-----------------------+
1 row in set (0.00 sec)

I'm glad the bug this caused had a minor impact, and this will hopefully be sufficient to slap me out of my loosely typed comfort zone for a while.

0 TrackBacks

Listed below are links to blogs that reference this entry: MySQL NULL gotcha; or, yes, Virginia, types do matter.

TrackBack URL for this entry: http://www.mattwallace.net/mt-tb.cgi/181

Leave a comment

September 2010

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Creative Commons License
This weblog is licensed under a Creative Commons License.

About The Author

Matt Wallace is a cloud computing architect, and recovering Web Application Developer working on a large e-commerce site and dabbling in social networking applications. He has recurring dreams of manipulating the real world with jQuery.