compute histogram in postgres