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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -