Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. array ('hello world', 'foo', 'bar') -- terms here have only letters and one space at most
  2.  
  3. CREATE OR REPLACE FUNCTION my_stupid_query(q text)
  4. RETURNS text[] AS $$
  5.  
  6. SELECT ARRAY(
  7. SELECT regexp_replace(t, '[^[:alpha:]]', '_', 'g')
  8. FROM unnest(string_to_array(q, ' ')) AS q(t)
  9. );
  10.  
  11. $$ LANGUAGE sql
  12. IMMUTABLE;
  13.  
  14. SELECT word
  15. FROM (VALUES (ARRAY['hello world', 'foo', 'bar'])) AS t1(x)
  16. CROSS JOIN (VALUES ('foo hello-world helloXworld') ) AS query(q)
  17. CROSS JOIN unnest(x) AS t2(word)
  18. WHERE NOT word LIKE ANY(my_stupid_query(q));
  19.  
  20. word
  21. ------
  22. bar
  23. (1 row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement