Word frequencies from strings in Postgres?

后端 未结 3 976
长情又很酷
长情又很酷 2020-12-28 09:35

Is it possible to identify distinct words and a count for each, from fields containing text strings in Postgres?

3条回答
  •  余生分开走
    2020-12-28 09:52

    Should be split by a space ' ' or other delimit symbol between words; not by an 's', unless intended to do so, e.g., treating 'myWordshere' as 'myWord' and 'here'.

    SELECT word, count(*)
    FROM ( 
      SELECT regexp_split_to_table(some_column, ' ') as word
      FROM some_table
    ) t
    GROUP BY word
    

提交回复
热议问题