postgresql - Look up in a white space separated string in Postgres -
i have character varying
field in postgres containing 1-white-space-separated set of strings. e.g.:
--> 1 2 3 <--
--> apples bananas pears <--
i put -->
, <--
show strings start , end (they not part of stored string itself)
i need query field find out if whole string contains word (apple instance). possible query
select * table thefield '%apple%'
but sucks , won't scale b-tree indexes scale if pattern attached beginning of string while in case searched string positioned anywhere in field.
how recommend approaching problem?
consider database-normalization first.
while working current design, support query trigram index, pretty fast.
more details , links in closely related answer:
postgresql query performance variations
even more pattern matching , indexes in related answer on dba.se:
pattern matching like, similar or regular expressions in postgresql
Comments
Post a Comment