title: Does PostgreSQL support precision and scale for Rails?
body: <p>I have an Rails application that defines a migration that contains a decimal with precision 8 and scale 2. The database I have set up is PostgreSQL 9.1 database.</p>
  
  <pre><code>class CreateMyModels &lt; ActiveRecord::Migration
      def change
          create_table :my_models do |t|
              t.decimal :multiplier, precison: 8, scale: 2
              t.timestamps
          end
      end
  end
  </code></pre>
  
  <p>When I run <code>rake db:migrate</code>, the migration happens successfully, but I noticed an error when I was trying to run a <code>MyModel.find_or_create_by_multiplier</code>. If I ran the following command twice, the object would get created twice:</p>
  
  <pre><code>MyModel.find_or_create_by_multiplier(multiplier: 0.07)
  </code></pre>
  
  <p>I am assuming this should create the object during the first call and then <strong>find</strong> the object during the second call. Unfortunately, this does not seem to be happening with the multiplier set to 0.07.</p>
  
  <p>This <strong>DOES</strong> work as expected for every other number I have thrown at the above command. The following commands work as expected (creating the object during the first call and then finding the object during the second call).</p>
  
  <pre><code>MyModel.find_or_create_by_multiplier(multiplier: 1.0)
  
  MyModel.find_or_create_by_multiplier(multiplier: 0.05)
  
  MyModel.find_or_create_by_multiplier(multiplier: 0.071)
  </code></pre>
  
  <p>When I view the PostgreSQL database description of the MyModel table, I notice that the table does not have a restriction on the numeric column.</p>
  
  <pre><code>   Column    |            Type             |                         Modifiers
  -------------+-----------------------------+-------------------------------------------------------
   id          | integer                     | not null default nextval('my_models_id_seq'::regclass)
   multiplier  | numeric                     | 
   created_at  | timestamp without time zone | not null
   updated_at  | timestamp without time zone | not null
  </code></pre>
  
  <p>My db/schema.rb file also does not state the precision and scale:</p>
  
  <pre><code>ActiveRecord::Schema.define(:version =&gt; 20121206202800) do
  
  ...
      create_table "my_models", :force =&gt; true do |t|
          t.decimal  "multiplier"
          t.datetime "created_at",                   :null =&gt; false
          t.datetime "updated_at",                   :null =&gt; false
      end
  ...
  </code></pre>
  
  <p>So my first question is, why do I not see precision and scale pushed down to PostgreSQL when I migrate? <a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column" rel="noreferrer">Documentation states that it should be supported</a>.</p>
  
  <p>My second question is, why is 0.07 not correctly comparing using the <code>MyModel.find_or_create_by_multiplier(multiplier: 0.07)</code> command? (If I need to open another question for this, I will).</p>