Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the integer size limit different on Rails when using PostgreSQL v. MySQL?

I'm migrating my app from MySQL to Postgres. If I do a rake db:schema:load, it loads fine into Postgres, and all my tests pass.

If I do rake db:migrate:reset, then an integer column that I had previously set to have :limit => 1 is set to have :limit => 2.

My migration sets it like so:

t.integer "foo", :limit => 1, :null => false

Is it simply a matter of Postgres having a lower minimum size?

like image 778
John Bachir Avatar asked Apr 11 '12 04:04

John Bachir


People also ask

What is better MySQL or PostgreSQL?

Most developers will tell you that MySQL is better for websites and online transactions, while PostgreSQL is better for large and complicated analytical processes.

Is PostgreSQL faster than MySQL?

PostgreSQL vs MySQL: Speed Speed however is a benchmark that will be decided based on how the Database is being utilized. PostgreSQL is faster when dealing with massive datasets, complicated queries, and read-write operations. On the other hand, MySQL is known to be faster for read-only commands.

Is PostgreSQL slower than MySQL?

Previously, Postgres performance was more balanced, i.e., reads were generally slower than MySQL, but then it improved and can now write large amounts of data more efficiently, making concurrency handling better.

Why is MySQL more popular than PostgreSQL?

MySQL is more popular than PostgreSQL for historical reasons. These are the major ones (in retrospect): MySQL was more leaner and faster in some (widely used) use cases since it had less features. Even though it was not the best, MySQL's replication system was very simple to setup and maintain.


2 Answers

The smallint type in PostgreSQL occupies two byte and accepts numbers from -32768 to +32767.

There is no tinyint like in MySQL that occupies 1 byte and accepts numbers from -128 to 127.

like image 151
Erwin Brandstetter Avatar answered Oct 16 '22 01:10

Erwin Brandstetter


Postgres doesn't provide a 1-byte integer type. The smallest datatype for integer is the 2-byte smallint.

like image 39
Lukas Eklund Avatar answered Oct 16 '22 00:10

Lukas Eklund