Created
October 15, 2019 19:31
-
-
Save mhkeller/b3c4e11815038e57addaf471435aed7d to your computer and use it in GitHub Desktop.
count occurrences of a string across rows of a pgsql table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--useful for seeing if a css class exists across all instances of scraped pages in a pgsql database | |
--adapted from here https://stackoverflow.com/questions/36376410/counting-the-number-of-occurrences-of-a-substring-within-a-string-in-postgresql | |
select sum(array_length(string_to_array(html, 'SELECTOR'), 1) - 1) from TABLE_NAME | |
--should equal rows in the table | |
--or this to get occurrences per row | |
select (array_length(string_to_array(html, 'SELECTOR'), 1) - 1) as ct from TABLE_NAME ORDER BY ct DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment