Skip to content

Instantly share code, notes, and snippets.

@josephcc
Last active August 1, 2017 20:07
Show Gist options
  • Save josephcc/d0a96800b24af6dbb98d29dee0953507 to your computer and use it in GitHub Desktop.
Save josephcc/d0a96800b24af6dbb98d29dee0953507 to your computer and use it in GitHub Desktop.
SELECT
string_agg(token, ' ') as ngram,
count(*) as count,
review_id,
MIN(start) AS start, MAX("end") AS end,
CASE
WHEN token = 'guy' THEN
index + 1
WHEN token = 'stand' THEN
unnest(ARRAY[index, index+1])
ELSE
index
END AS _index
FROM
index
WHERE
city = 'Tempe' AND
token IN ('guy', 'stand', 'behind')
GROUP BY _index, review_id
HAVING string_agg(token, ' ') in ('guy stand', 'stand behind')
ORDER BY count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment