Skip to content

Instantly share code, notes, and snippets.

@workmad3
Last active August 29, 2015 14:03
Show Gist options
  • Save workmad3/5e8e74d1c6695f309ac0 to your computer and use it in GitHub Desktop.
Save workmad3/5e8e74d1c6695f309ac0 to your computer and use it in GitHub Desktop.
Foo.transaction do
Foo.connection.execute("CREATE TEMPORARY TABLE temp_foos ON COMMIT DROP AS (SELECT *, RANDOM() AS rank FROM foos)")
Foo.select("temp_foos.*").from("temp_foos").order("rank").find_each do |foo|
#whatever
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment