Skip to content

Instantly share code, notes, and snippets.

@searls
Created July 5, 2018 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searls/cb59744b49b3beb0a4d2d1573d7f4299 to your computer and use it in GitHub Desktop.
Save searls/cb59744b49b3beb0a4d2d1573d7f4299 to your computer and use it in GitHub Desktop.
-- Query to find for a given array of strings whether a PG array
-- column of strings matches any of the given strings after being
-- trimmed and uppercase (where && is the intersection operator)
SELECT assignments.*
FROM assignments
WHERE assignments.user_id = 42
AND (upper(regexp_replace(synonyms::text, '\s+', '', 'g'))::text[]
&& ARRAY['THING1','THING2']::text[])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment