A postgresql function to generatie a histogram.