bakineggs

one spec at a time

My name is Dan Barry. I've been a programming enthusiast for over ten years now.

Professionally, I've been developing web applications using Ruby on Rails. For fun, I'm writing a language called okk.

I'm currently living in San Francisco, California where I work as a software engineer at Square.

Blog

May 25, 2009 @ 10:13am

Using a Float Column in a Where Clause

I spent about 12 hours today trying to figure out why one of my validates_uniqueness_of constraints was not working. Here's why:

mysql> create table some_table (some_float_column float);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into some_table (some_float_column) values (8.4537);
Query OK, 1 row affected (0.00 sec)

mysql> select * from some_table where some_float_column = 8.4537;
Empty set (0.01 sec)

Notice how I'd just inserted a row with that value yet the row was not returned. All I had to do was change the float column to a decimal column.

Post Comment

© 2008-2012 Dan Barry. Designed by Hunter Hastings.