Feature #775
Database Data Types for ActiveRecord with Ruby on Rails
Description
There are many different types of data types used for database tables with Ruby on Rails, each different database backend having their own data types. This is just a simple list of generic data types used with ActiveRecord with Ruby on Rails.
:string
¶
- Limited to 255 characters (depending on DBMS)
- Use for short text fields (names, emails, etc)
:text
¶
- Unlimited length (depending on DBMS)
- Use for comments, blog posts, etc. General rule of thumb: if it's captured via textarea, use Text. For input using textfields, use string.
:integer
¶
- Whole numbers
:float
¶
- Decimal numbers stored with floating point precision
- Precision is fixed, which can be problematic for some calculations; generally no good for math operations due to inaccurate rounding.
:decimal
¶
- Decimal numbers stored with precision that varies according to what is needed by your calculations; use these for math that needs to be accurate
- See this post for examples and an in-depth explanation on the differences between floats and decimals.
:boolean
¶
- Use to store true/false attributes (i.e. things that only have two states, like on/off)
:binary
¶
- Use to store images, movies, and other files in their original, raw format in chunks of data called blobs
:date
¶
- Stores only a date (year, month, day)
:time
¶
- Stores only a time (hours, minutes, seconds)
:datetime
¶
- Stores both date and time
:timestamp
¶
- Stores both date and time