Writing raw SQL queries

If you really, really have a good reason to write raw SQL (generally a bad practice), make sure you use the right call.

Avoid ActiveRecord::Base.connection.execute in general, in particular because Octopus relies on this to determine which queries go to replicas. execute would always go to the master.

A number of other methods Show archive.org snapshot are available: select_value, select_rows, of update being the most usual.

Julien Letessier Over 11 years ago