Postgresql Count Distinct Substrings