Ruby on Rails Wednesday, January 28, 2015

After running a migration I noticed that rails is changing the specified
decimal data type in PostgreSQL. Is there a reason for that?

According to this post:
http://stackoverflow.com/questions/1841915/difference-betweeen-decimal-and-numeric
I found that there is a slight difference between decimal type and
numeric type:


NUMERIC must be exactly as precise as it is defined — so if you define 4
decimal places, the DB must always store 4 decimal places.

DECIMAL must be at least as precise as it is defined. This means that
the database can actually store more digits then specified (due to the
behind-the-scenes storage having space for extra digits). This means the
database might store 1.00005 instead of 1.0000, affecting future
calculations.


class CreateBooks < ActiveRecord::Migration
def change
create_table :books, id: :uuid do |t|
t.decimal :price
t.string :title
t.timestamps
end
end
end

After running this migration, the column price is of numeric type
instead of decimal.

Any feedback is appreciated

Rod

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/15138c4c6b5b53e9b4c568f146787d06%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment