How to count unique values?
SELECT COUNT(DISTINCT ip_address) FROM bandits
As mentioned here: https://stackoverflow.com/questions/11250253/postgresql-countdistinct-very-slow, it could be much faster to use a bit longer version instead:
SELECT count(*) FROM (SELECT DISTINCT ip_address FROM bandits) AS bandits_distinct