Skip to content

Instantly share code, notes, and snippets.

@hemju
Created July 24, 2013 11:01
Show Gist options
  • Save hemju/6069662 to your computer and use it in GitHub Desktop.
Save hemju/6069662 to your computer and use it in GitHub Desktop.
Shows two queries to get the word count and character count of a string/text column in Postgres.
# Character count
select sum(length(YOUR_COLUMN)) from YOUR_TABLE;
# Word count
select sum(array_length(regexp_split_to_array(YOUR_COLUMN, '\s'),1)) from YOUR_TABLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment