Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the Rails datatypes?

I know that Rails datatypes can be found here:

Rails 4: List of available datatypes

or here:

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column

but what I can't find is a clear definition of each, and the differences between, say, a float versus a decimal, or a string versus text.

Where can I find in-depth definitions of the datatypes?

like image 994
Choylton B. Higginbottom Avatar asked Sep 26 '13 16:09

Choylton B. Higginbottom


2 Answers

Here's a good set of definitions (from https://stackoverflow.com/a/15316528/2128691)

  • binary - is for storing data such as images, audio, or movies.
  • boolean - is for storing true or false values.
  • date - store only the date
  • datetime - store the date and time into a column.
  • decimal - is for decimals.
  • float - is for decimals. (What's the difference between decimal and float?)
  • integer - is for whole numbers.
  • primary_key - unique key that can uniquely identify each row in a table
  • string - is for small data types such as a title. (Should you choose string or text?)
  • text - is for longer pieces of textual data, such as a paragraph of information.
  • time - is for time only
  • timestamp - for storing date and time into a column.
like image 50
dax Avatar answered Sep 30 '22 17:09

dax


Rails is built on the Ruby language, so try searching for Ruby datatypes instead!

http://www.rubybacon.com/ruby-data-types/ (link no longer working)

Updated link

http://ruby-for-beginners.rubymonstas.org/built_in_classes.html

like image 22
Tyler Avatar answered Sep 30 '22 16:09

Tyler