hamperbot / hamper

an irc bot
MIT License
19 stars 42 forks source link

karma: Fix --top and --bottom on PostgreSQL. #102

Closed magical closed 9 years ago

magical commented 9 years ago

Postgres is really picky about queries containing GROUP BY. Every column which isn't listed in the GROUP BY clause has to be wrapped up in an aggregate function.

The problem was that we were generating queries like this:

SELECT karmastats.receiver AS karmastats_receiver, sum(karmastats.kcount) AS anon_1
FROM karmastats GROUP BY karmastats.receiver ORDER BY karmastats.kcount

Note the unadorned karmastats.kcount in the ORDER BY clause. The fix is to use sum(karmastats.kcount) everywhere.

justinnoah commented 9 years ago

Nice work, I like the cleanup as well.