Last active
October 11, 2018 08:42
-
-
Save varunchitale/440027e522f35d17516b86d3d68b8f03 to your computer and use it in GitHub Desktop.
Materialized View operations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Create the materialized view | |
CREATE materialized view <schema_name>.mv_prompts AS | |
SELECT id, ngram, freq | |
FROM <schema_name>.prompts | |
WHERE add_conditions_here | |
ORDER BY freq DESC; | |
--Create a search index using GIN | |
CREATE INDEX prompts_ngram_idx | |
ON <schema_name>.mv_prompts | |
USING GIN (to_tsvector('english', ngram)); | |
--Refresh this view when needed | |
REFRESH MATERIALIZED VIEW <schema_name>.mv_prompts WITH DATA; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment