Selecting random in rails sqlite vs mysql Selecting random in rails sqlite vs mysql sqlite sqlite

Selecting random in rails sqlite vs mysql


You can effectively alias MySQL's rand() to the standard random() by creating a function:

CREATE FUNCTION random() RETURNS FLOAT NO SQL SQL SECURITY INVOKER RETURN rand();


I ran into this problem when developing locally using SQLite. Unfortunately, this is not the only difference between the databases you're going to run into (booleans are also handled differently for instance).

Is it a requirement that you support both SQLite and MySQL? If not I recommend switching to a single database: the one you're deploying on in production.

This takes a bit more time to set up but IMHO in the long run it will save you time, and you will have confidence that your app works well on the database that you'll actually be deploying it with.