Skip to content

Instantly share code, notes, and snippets.

@toddsiegel
Last active February 5, 2024 19:00
Show Gist options
  • Save toddsiegel/ca547cfdb0ca12bb556959f860684bc5 to your computer and use it in GitHub Desktop.
Save toddsiegel/ca547cfdb0ca12bb556959f860684bc5 to your computer and use it in GitHub Desktop.
PostgreSQL Histogram
-- this groups by 5 to keep the length down
select length(username) as length,
count(*) as count,
repeat('*'::text, (COUNT(length(username))::int / 5) + 1) AS histogram
from users
where username is not null
group by length(username)
order by length;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment