countで重複を除くとは?
まぁそのままですがrailsとpostgresでcountするときに重複を除く方法です。
環境
rails1.2.6
postgresql8.4.4
table1
user_id
-----
1
2
1
-----
1
2
1
PostgreSQLでの使用方法
SELECT count(*) FROM table1;
=> 3
SELECT count(DISTINCT user_id) FROM table1;
=> 2
=> 3
SELECT count(DISTINCT user_id) FROM table1;
=> 2
Ruby on Railsでの使用方法
Hoge.count
=> 3
Hoge.count(:user_id, :distinct => true)
=> 2
=> 3
Hoge.count(:user_id, :distinct => true)
=> 2
