Skip to content

Instantly share code, notes, and snippets.

@localhostdotdev
Created February 10, 2019 16:42
Show Gist options
  • Save localhostdotdev/2db2f7364fb827d9906834a4182a873b to your computer and use it in GitHub Desktop.
Save localhostdotdev/2db2f7364fb827d9906834a4182a873b to your computer and use it in GitHub Desktop.
gem 'rails', github: 'rails/rails'
require 'active_record'
`dropdb bug_1; createdb bug_1`
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'bug_1',
host: 'localhost',
username: 'postgres'
)
ActiveRecord::Schema.define do
create_table :settings do |t|
t.string :key
t.string :value
end
end
class Setting < ActiveRecord::Base
end
Setting.create!(key: "a", value: "1")
Setting.create!(key: "a", value: "2")
Setting.create!(key: "c", value: "3")
puts "Setting.select('DISTINCT key').size"
p Setting.select('DISTINCT key').size
puts "Setting.select('DISTINCT key').to_a.size"
p Setting.select('DISTINCT key').to_a.size
puts "Setting.select('DISTINCT ON (key) *').size"
p Setting.select('DISTINCT ON (key) *').size
puts "Setting.select('DISTINCT ON(key) *').to_a.size"
p Setting.select('DISTINCT ON(key) *').to_a.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment