Dev Bit: SQL word count & character count with Postgres

Helmut Michael Juskewycz
ยท 1 min read
Post featured image

At LingoHub we utilize Postgres and Elasticsearch to handle our large text base. Is there a way to do an SQL word count for our translations? There is. I wanted to share with you two SQL queries for character count and word count of a text column:

# 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;

Latest articles

Clock calendar notifications in harmony

Start your 14-day free trial